In View(CakePHP), the proper way to get current controller?

前端 未结 8 850
伪装坚强ぢ
伪装坚强ぢ 2021-02-02 07:36

In View, I can get action by using

$this->action

But, I cannot get controller name by

$this->controller
8条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 08:20

    $this->name also give you controller's name. Their difference with $this->params['controller'] is it's first letter capitalized

    debug($this->name);
    debug($this->params['controller']);
    

    Results in:

     \app\Controller\AppController.php (line 176)
    
    'Users'
    
    \app\Controller\AppController.php (line 177)
    
    'users'
    

提交回复
热议问题