我想获取处理当前操作的当前 Controller 名称。 但就我而言,我将在我的布局文件中的 main.php 中查找当前 Controller 。
这是我的目录结构的小 View ,让您了解我的布局文件在哪里,以及我将在搜索 Controller 名称时放置代码的文件
- /protected
- /themes
- /mylayout
- /layouts
- main.php
- column1.php
- column2.php
- /site
- index.php
这可能吗?我正在尝试以下代码,但未能获得我当前的 Controller 名称...
echo Yii::app()->controller->getId;
echo Yii:app()->getController->id;
echo Yii:app()->controller->uniqueID;
谢谢
最佳答案
像这样
Yii::app()->controller->id
或
Yii::app()->getController()->getId()
http://www.yiiframework.com/doc/api/1.1/CApplication#getController-detail
关于php - 在 Yii 中获取当前 Controller ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9582237/