Get Name of Current Controller and Action in Yii

By | December 5, 2011

This is a simple one line piece of code to retrieve the name of the current controller, which is great for making more generic and useful code.

$controllerName = Yii::app()->controller->id;

2 Comments

shahid on December 7, 2011 at 9:39 am.

wrong. use this “$this->getId()”. Done!

Nick Holdren on December 7, 2011 at 12:02 pm.

Agreed, that works as well but only in the context of the controller class. My example should work throughout the application.

Leave Your Comment

Your email will not be published or shared. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>