Thinkphp5-前置操作

来源:互联网 发布:淘宝红包链接转手机端 编辑:程序博客网 时间:2024/06/08 17:38
<?phpnamespace app\index\controller;use think\Controller;class Index extends Controller{    protected $beforeActionList = [        'first',                                //在执行所有方法前都会执行first方法        'second' =>  ['except'=>'hello'],       //除hello方法外的方法执行前都要先执行second方法        'three'  =>  ['only'=>'hello,data'],    //在hello/data方法执行前先执行three方法    ];    protected function first()    {        echo 'first<br/>';    }    protected function second()    {        echo 'second<br/>';    }    protected function three()    {        echo 'three<br/>';    }    public function hello()    {        return 'hello';    }    public function data()    {        return 'data';    }}

如注释所言,为TP5的前置操作。
在以下URL中访问:

http://127.0.0.1/demo/public/index.php/index/index/hello

有如下显示:
first
three
hello