Thinkphp5的前置方法列表.
2019-03-13 本文已影响0人
ZSGZ_AD
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;
}
}
![](https://img.haomeiwen.com/i7044412/4b969ced94a5f651.png)
![](https://img.haomeiwen.com/i7044412/ee132179df2e054d.png)
![](https://img.haomeiwen.com/i7044412/426af16d3f3b1bd8.png)