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:

http://example.com/plugin_name/controller_name/action_name

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'));

Output:

http://example.com/controller_name/action_name

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

http://example.com/plugin_name/controller_name_1/action_name_1
http://example.com/plugin_name/controller_name_2/action_name_2
http://example.com/plugin_name/controller_name_3/action_name_3


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!