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

2020-05-19 21:20发布

In View, I can get action by using

$this->action

But, I cannot get controller name by

$this->controller

What is the proper way to get current controller in View?

标签: cakephp-2.0
8条回答
闹够了就滚
2楼-- · 2020-05-19 21:38

To get the current,

  • controller: $this->params['controller']
  • action: $this->params['action']
  • arguments:$this->params['pass']
查看更多
太酷不给撩
3楼-- · 2020-05-19 21:46

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')
查看更多
登录 后发表回答