tp5操作注意

1.数组注意: 

        $id = $this->request->param('id');
        $where['uid']=$id;
        $where['type']=1;
        $list = UserRecords::getList($where, '*', 'id desc');
        dump($list);die;
        foreach($list['data'] as $k=>$v){
            $list['data'][$k]['task_id']=Task::where(['id'=>$v['task_id']])->field('title')->find()['title'];

        }

 打印出来的结果:

array(5) {
  ["data"] => object(think\model\Collection)#154 (1) {
    ["items":protected] => array(2) {
      [0] => object(app\model\UserRecords)#151 (2) {
        ["data"] => array(10) {
          ["id"] => int(21)
          ["create_time"] => int(1572921365)
          ["uid"] => int(8)
          ["type"] => int(1)
          ["num"] => int(6)
          ["num_type"] => int(2)
          ["content"] => string(31) "发布活动"
          ["task_id"] => int(30)
          ["integral"] => int(58)
          ["duration"] => int(0)
        }
        ["relation"] => array(0) {
        }
      }
      [1] => object(app\model\UserRecords)#153 (2) {
        ["data"] => array(10) {
          ["id"] => int(20)
          ["create_time"] => int(1572920421)
          ["uid"] => int(8)
          ["type"] => int(1)
          ["num"] => int(14)
          ["num_type"] => int(2)
          ["content"] => string(31) "发布活动,暂"
          ["task_id"] => int(29)
          ["integral"] => int(64)
          ["duration"] => int(0)
        }
        ["relation"] => array(0) {
        }
      }
    }
  }
  ["count"] => int(2)
  ["code"] => int(0)
  ["current_page"] => string(1) "1"
  ["max_page"] => float(1)
}

2.增加模板静态文件注意:

 config 下的template.php配置

'template'               => [
        // 模板引擎类型 支持 php think 支持扩展
        'type'         => 'Think',
        // 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写
        'auto_rule'    => 1,
        // 模板路径
        'view_path'    => '',
        // 模板后缀
        'view_suffix'  => 'html',
        // 模板文件名分隔符
        'view_depr'    => DS,
        // 模板引擎普通标签开始标记
        'tpl_begin'    => '{',
        // 模板引擎普通标签结束标记
        'tpl_end'      => '}',
        // 标签库标签开始标记
        'taglib_begin' => '<',
        // 标签库标签结束标记
        'taglib_end'   => '>',
        // 静态文件路径替换
     // 模板页面使用<link rel="stylesheet" type="text/css" href="__ADMIN__/page.css">

        'tpl_replace_string' =>  [
            '__ADMIN__'     => '/static/Admin',
            '__Home__'      => '/static/Home',
            '__Wap__'       => '/static/Wap',
            '__Api__'       => '/static/Api'

        ]
      
    ]

 3.获取id

tp5:

insertGetId方法新增数据并返回主键值使用getLastInsID方法:

Db::name('user')->insert($data);

 $userId = Db::name('user')->getLastInsID();

// 使用insertGetId方法

Db::name('user')->insertGetId($data);

4.打印最后一条sql

Db::table('table_name')->getLastSql()

use think\Db;
dump( Db::getLastSql());

5.富文本信息解析

{{$web_connent|raw}}
只要在参数名字后面加上|raw,就能把传过来的富文本信息解析成HTML页面了。 

6, 打印日志

use Log;
Log::record($diadata);//输入runtime\log中
发布了173 篇原创文章 · 获赞 29 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/qq_29058883/article/details/102911672
tp5
今日推荐