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

你可能感兴趣的:(Thinkphp5的前置方法列表.)