<?php
namespace 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