I want to get the current controller name that handles the current action. but the in my case I will look for the current controller in my main.php in my layout files.
this is my small view of my directory structure to give you an idea where is my layout files and the file where i will put my codes in searching of my controller name
- /protected
- /themes
- /mylayout
- /layouts
- main.php
- column1.php
- column2.php
- /site
- index.php
Is this possible? im trying the following codes but i failed to get my current controller name...
echo Yii::app()->controller->getId;
echo Yii:app()->getController->id;
echo Yii:app()->controller->uniqueID;
thanks
Controllers are part of the MVC architecture. They are objects of classes extending from yii\base\Controller and are responsible for processing requests and generating responses.
Applications are objects that govern the overall structure and lifecycle of Yii application systems. Each Yii application system contains a single application object which is created in the entry script and is globally accessible through the expression \Yii::$app .
Like this
Yii::app()->controller->id
or
Yii::app()->getController()->getId()
http://www.yiiframework.com/doc/api/1.1/CApplication#getController-detail
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With