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

前端 未结 8 851
伪装坚强ぢ
伪装坚强ぢ 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:10

    For cakephp 3.6 and later:

    Although above solutions will work but it gives deprecated warning and will not work in cakephp 4. So It is better to use the following code to get the controller name. It will work in view page and controllers as well.

    $this->request->getParam('controller')
    

提交回复
热议问题