Friday, January 29, 2010

Managing Plugin URL in CakePHP

Just now I noticed my urls are getting deformed when I tried to access a plugin controller/action in my brand new CakePHP app. It took me sometime to understand that the problem was due to plugin call. When you are calling plugin controller/action - the url structure is:

 echo $html->link('Plugin Controller/Action Link', array('plugin' => 'plugin_name', 'controller' => 'controller_name', 'action' => 'action_name'));

The output will be:

Make sure to mention 'plugin' => null in remaining urls, if you do not want to show plugin_name in other displayed links.

 echo $html->link('Non Plugin Link', array('plugin' => null, 'controller' => 'controller_name', 'action' => 'action_name'));


If you do not specify 'plugin' => null, all the displayed links will show:

From this what I get is that it is better to specify 'plugin' => null in case of all non-plugin links which are likely to be displayed in tandem with plugin links.

Or, there may be a short route - who knows?

Cake rocks... still learning each day...

1 comment:

David said...

awesome thanks buddy!