Get Controller, Action, URL information from Views/Elements
It is sometime very useful to know the name of the controller/action that is calling the view/elements.
Suppose you want to create a menubar/navigation element, where you want to highlight the menuitem which is now active. Now, it will be easier for you to highlight the menuitem accordingly if you can get the url or controller/action name from the element’s code.
You can get this easily, every view or element gets a parameter by default in cakePHP called $params. The $params is an associative array that looks like-
Array (
[controller] => controller_name
[action] => action_name
[url] => Array ( [url] => cake_url )
)
So, by calling $params['url']['url'] from your views/elements you will get the current url. Thanks.
About this entry
You’re currently reading “Get Controller, Action, URL information from Views/Elements,” an entry on anupom.toString( );
- Published:
- January 8, 2007 / 5:26 pm
- Category:
- CakePHP
- Tags:
2 Comments
Jump to comment form | comments rss [?] | trackback uri [?]