Thinkphp5的前置方法列表.

class Index extends \think\Controller
{
    protected $beforeActionList =[ //前置方法列表,继承自Controller
        'before1' => '', //为空,表示before是当期类中的全部操作的前置操作
        'before2' => ['only'=>'demo2'], //only仅适用
        'before3' => ['except'=>'demo1,demo2'],//except排除
    ];
    protected $siteName ='默认值'; //自定义属性
    protected function before1(){
         $this->siteName = $this->request->param('name'); //获取url中访问的name值;
    }
    protected function before2(){

        $this->siteName = '口袋里的';
    }
    protected function before3(){

        $this->siteName = '创新高低,大湖名城~';
    }
    public function demo1()
    {
     return $this->siteName;
    }

    public function demo2()
    {
        return $this->siteName;
    }
    public function demo3()
    {
        return $this->siteName;
    }


}
image.png

image.png

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容