HtmlHelper url/link hack for using your main layout in a plugin
Created: 2008-06-27 09:02:02, last updated: 2008-06-27 09:03:32
When we include our main layout from a plugin, a prefix is added to all $html->link() method calls, breaking our links. A solution is to set plugin = null on each call but it isn't very DRY. Talking with one of my friends, Walter, we arrive to the following code.
At the top and bottom of your layout file add:
$_this =& Router::getInstance(); $params = $_this->__params; $_this->__params[0]['plugin'] = null; // your // layout // code ... $_this->__params = $params; unset($params);
This is an ugly hack, but we remove the plugin option in the global parameters that cake uses to add the plugin prefix, so all calls to Router::url() here will not be seen as in the context of a plugin. At the end of the layout we restore the global parameters.
0 comments