You know sometimes, in CakePHP’s views, it is useful to check what is the controller’s action. It is quite useful when it comes to implementing selected tabs.

You can use the following expression to get the action name from your view:

[code lang=“php”]$this->controller->action[/code]

The following is a usage example:

[code lang=“php”]<?php /* This is a view element file - nav_messages.thtml */ ?>

<?php $s = $this->controller->action; ?>

[/code]

[ad#highlight]

“messages_inbox” and “messages_sentbox” is the name of the action (function) in my controller.

This way you can get the list tabs to be selected visually. There is a class named “selected” that is defined in the CSS. I tested this on CakePHP 1.1. The code works if it’s in an element too.

I just realized my code font size is too huge.

comments powered by Disqus