|
- <?php
- namespace app\articles\controller;
- // 前置方法第一步:继承controller类
- class Beforem extends \think\Controller
- {
- private $laomo ;
- // 前置方法第二步 继承基类的前置方法
- // 2.1创建前置操作方法
- // 2.2 配置前置操作列表
- protected $beforeActionList = [ //前置方法列表
- // 参数理解 键就是前置方法,值就是操作
- 'before1' => '', //如果是空 表示默认是当前类所有方法的前置操作
- 'before4' => ['only'=>'tv4'], //before4 仅对 tv4操作有效
- 'before2' => ['except'=>'tv1,tv4'] // 表示对除了1和4以外的方法都有效
- ];
- protected function before1()
- {
- $this->laomo = $this->request->param('lmname'); //这句话的赋值是错的
- // 这个参数在哪呢 在URL里
- // http://localhost/public/index.php/articles/beforem/tv1/lmname/yh
- }
- // 前置操作变量赋值 看下接收方法
- // $this->request->param('name') 表示接收 变量$name 的值 在这里有个大坑, 视频里的教程
- // url_param_type' => 0,并没有改过来, 而我接路由的继续做 该值被我改成了1 所以没有读取到name的值 改回0即可
-
- protected function before2()
- {
- $this->laomo ='这是before2的前置方法赋值 }
- protected function before4()
- {
- $this->laomo ='这是before4的前置方法赋值 }
- public function tv1(){
- return $this->laomo;
- }
- public function tv4(){
- return $this->laomo;
- }
- public function tv5(){
- return $this->laomo;
- }
- public function tv2($a){
- $this->laomo =$a;
- return $this->laomo.'赋值成功 }
- public function tv3($b){
- $this->laomo =$b;
- return $this->laomo.'这是tv3的方法 赋值 }
- }
复制代码 我敲个代码 我容易吗 ! TP5 只有前置操作 ,没有后置操作
|
|