ThinkPhp_5框架开发【整理】

==================================================

ThinkPhp_5心得笔记

------------------------------------------------------------------------

public function test()
{
$comment = new Comment();
$comment->object::get($comment->object_id);
}
-----------
if(!request()->isPost()){
}else{
  $data = input('post.);
}

session(null, 'user');
// 跳出
return $this->redirect(url('login/index'));

===================================

// allowField 过滤data数组中非数据表中的数据
return $this->allowField(true)->save($data, ['id'=>$id]);

 

 

<!--包含头部文件-->
{include file="public/header" /}

-------

<!--包含footer文件-->
{include file="public/footer" /}

------------------------------------------------------------------------

输出控制器:echo request()->controller();

$request = Request::instance();
echo "当前模块名称是" . $request->module();
echo "当前控制器名称是" . $request->controller();
echo "当前操作名称是" . $request->action();

 

 unset($data['id'])  //删除单个数组中的值

----------------------------------------------------------------------

function isright_format(value,row,index){
  return value==1         ?           '<span style="color:red;">教学助理</span>'  :  '<span style="color:#7df;">非助理</span>';
}

 ---------------------------------------------------------------------

<input type="text" name="captcha" placeholder="请输入验证码" required=""><br>
<img src="<{:captcha_src()}>" width="95" height="45" οnclick="this.src='<{:captcha_src()}>'"><br><br>

$captcha = $_REQUEST['captcha'];
if(!captcha_check($captcha)){
  //验证失败
  $this->error('验证码输入错误');
}else{
  $this->success('成功',url('user/login'));
}

 ----------------------------------------------------------------------------

 

$result=$this->validate($data,'Student');

 return $this->success('登录成功');

 return $this->error('验证码输入错误,请从新输入');

 return $this->fetch('index');

 return view();

 return redirect("$cc/index/index");

--------------------------------------------------------------------------------------

//循环输出一级栏目

<{volist name="category" id="vo"}>
  <a class="nav-a" href="#" ><li class=""><{$vo.catname}></li></a>
<{/volist}>

 

 <{:url('    admin     ')}>    ——方法不存在

 

控制器不存在:app\member\controller\Admin:

 

Route::any('adminapi/v1/login','adminapi/v1.login/index');
【模块/控制器/方法】

<{:url('    admin  /  index       ')}>

 -------------------------------------------------------------------------------------

use app\common\model\Classcourse as Classcourse_Model;

 

$stu = new Classcourse_Model();
$cnt = $stu->allowField(true)->save($data);

--------------------------------------------------------------------------------

 //跳转页面

 οnclick="loadtea()"

function loadtea(){
  url="<{:url('all')}>";
}

 

 -----------------------------------------------------------------------

 

public function index()
{
// 模板变量赋值
$this->assign('name','ThinkPHP');
$this->assign('email','thinkphp@qq.com');
// 或者批量赋值
$this->assign([
  'name' => 'ThinkPHP',
  'email' => 'thinkphp@qq.com'
]);
// 模板输出
  return $this->fetch('index');
}

 

 

============================================================================================

安装:

①官网:http://www.thinkphp.cn/

//访问模型

http://localhost/tp5/public/index.php/admin

-------------------------------------------------------------------------------------------------------------------

__STATIC__:/tp5/static

$_REQUEST

 

 

-------------------------------------------------------------------------------------------------------------------

 路径:application/config.php

// 视图输出字符串内容替换
'view_replace_str' => ['__EASYUI__'=>'/tp_scoring/public/static',
    '__EXTEND__'=>'/tp_scoring/extend',
    '__IMG__'=>'/tp_scoring/public/static/img'

  ],

//加载与方法同名的页面
return $this->fetch();

// return view();

============================= 分页

$status = $_GET['status'];
$list = db('user')->where('user_type',$status)->order('id desc')->
paginate(10,false,['query'=>array('status'=>$status)]);

 ----------------------------------------

 

 

 

 

 

 

 

-----------------------

//账户记录
$where = 'sign=1';

if (input('get.keywords')) {
$keywords = input('get.keywords');
$str = ' user_name like "%' . input("get.keywords") . '%" or id="'.$keywords.'"';
$user_id = db('user')->where($str)->value('id');
if($user_id){
$where .= ' and user_id ='. $user_id;
}
}

user_name like "%


if (input('get.start')) {
$starttime = strtotime(input('get.start'));
$where .= ' and add_time >= "' . $starttime . '"';
}

if (input('get.end')) {
$endtime = strtotime(input('get.end')) + 86400;
$where .= ' and add_time <= "' . $endtime . '"';
}

 

$list = db('prize_log')->order('id desc')->where($where)->paginate(10);
$this->assign('page', $list->render());//先将page赋值出来

$list = db('prize_log')->order('id desc')->where(sign=1 and add_time <= "' . $endtime)->paginate(10);

-----------------------------------------------------------------------------

// 定义demo模块的自动生成 (按照实际定义的文件名生成)
'demo' => [
'__file__' => ['common.php'],
'__dir__' => ['behavior', 'controller', 'model', 'view'],
'controller' => ['Index', 'Test', 'UserType'],
'model' => ['User', 'UserType'],
'view' => ['index/index'],
],

// 定义admin模块的自动生成 (自己定义的admin)
'admin' => [
'__file__' => ['common.php'],
'__dir__' => [ 'controller', 'validate', 'view'],
'controller' => ['Base', 'Index', 'Test'],
'validate' => ['User', 'Category'],
'view' => ['Index/index','Public/header','Public/footer'],
],
// 定义common模块的自动生成 (自己定义的common)
'common' => [
'__file__' => ['common.php'],
'__dir__' => [ 'controller', 'model', 'validate'],
'controller' => [ 'Index'],
'model' => ['Admin','User', 'Category'],
'validate' => ['Bis'],
],
-------------------------------------------------------------------------------------
Base.php
<?php
namespace app\index\controller;
use think\Controller;

class Base extends Controller

-------------------------------------------------
user.php
<?php
namespace app\index\controller;
use think\Controller;

class User extends Controller



====================================模型调用
<?php
namespace app\index\controller;
use think\Controller;

class User extends Controller
{
try {
$res = model('User')->add($data);
}catch (\Exception $e) {
$this->error($e->getMessage());
}
-----------
<?php
namespace app\common\model;

use think\Model;

class User extends BaseModel
{
public function add($data = []) {
// 如果提交的数据不是数组
if(!is_array($data)) {
exception('传递的数据不是数组');
}

$data['status'] = 1;
return $this->data($data)->allowField(true)
->save();
}

/**
* 根据用户名获取用户信息
* @param $username
*/
public function getUserByUsername($username) {
if(!$username) {
exception('用户名不合法');
}

$data = ['username' => $username];
return $this->where($data)->find();
}
}
=======================================================================

$data = input('post.');
//dump($data);exit;
//halt($data);
//echo 12;exit;
//$data['status'] = 10;

debug('begin');
echo debug('begin','end')

$validate = validate('Category');
$data['name'] = htmlentities($data['name']);




$subsql = Db::table('think_work') ->where('status',1) ->field('artist_id,count(id) count') ->group('artist_id') ->buildSql(); Db::table('think_user') ->alias('a') ->join([$subsql=> 'w'], 'a.artist_id = w.artist_id') ->select();

转载于:https://www.cnblogs.com/vip-deng-vip/p/7801225.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值