thinkphp

thinkphp小知识

tp6定义全局常量位置:confing/view.php

跨控制器调用

thinkphp5

protected $service;
public function __construct(CenterOutService $service)
{
    parent::__construct();
    $this->service = $service;
}  

public function index()
{
    $this->assign(['list'  =>  $this->service->page()]);
    return view();
}

thinkphp6

$right=new \app\controller\Right($this->app);

模板页获取请求参数

tp6   $request= \think\facade\Request::instance();
tp5	$request= \think\Request::instance();

选项卡添加样式

<script>
    var className = '{$request->action()}_{$request->param("id")}'
    //$("."+className).addClass('active');
    $("."+className).prepend('<span/>');
</script>
<script>
	var className = '{$request->controller()}-{$request->action()}'
	$("."+className).addClass('active');
	$("."+className).parent().parent().addClass('active open');
	$("."+className).parent().show();
</script>

封装where查询条件

    public function page(){
        $data 	= Request::instance()->get();
        $where 	= [];
        //封装where查询条件
        (empty($data['status']) || $data['status'] == '')	|| $where['status'] = $data['status'];
        empty($data['name'])	|| $where['name']	= ['like','%'.$data['name'] ];
        empty($data['out_pack'])	|| $where['out_pack | in_pack'] 	= ['like','%'.$data['out_pack'].'%' ];
        return Company::where($where)->paginate(10);        
    }

验证码

<input name="captcha" type="text" maxlength="8" autocomplete="off" class="form-control" errormsg="请输入验证码!" datatype="*4-6" nullmsg="请输入验证码!">
<img title="点击刷新" src="{:captcha_src()}"  style="cursor:pointer"
 onclick="this.src='{:captcha_src()}?id='+Math.random()+''">

$captcha = $this->request->post('captcha');
if (!captcha_check($captcha)) {
      $this->error("验证码不正确");
}else{
       $this->success("正确");
}

thinkcmf 自动路由

            <td>
                <notempty name="vo.categories">
                    <a href="{:cmf_url('portal/Article/index',array('id'=>$vo['id'],'cid'=>$vo['categories'][0]['id']))}"
                       target="_blank">{$vo.post_title}666</a>
                    <else/>
                    <a href="{:cmf_url('portal/Article/index',array('id'=>$vo.id))}"
                       target="_blank">{$vo.post_title}</a>
                </notempty>
            </td>
            <td>
                <foreach name="vo.categories" item="voo">
                        <a class="label label-default"
                           href="{:cmf_url('portal/List/index',array('id'=>$voo['id']))}"
                           target="_blank"
                        >{$voo.name}</a>
                </foreach>
            </td>

模板标签

{$vo.post_content | htmlspecialchars_decode |raw |strip_tags| mb_substr=0,62}...
{$vo.pick_status==0?'正常':'废弃'} 
{:date('Y-m-d H:i',$user->add_time)} 
{$content->create_time|date="Y-m-d H:i:s",###}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值