Don’t add a component twice

Note: This post is over a year old and the content may no longer be accurate.

Last week I spent an annoyingly long time tracking down a bug caused by what was basically a simple typo.

I discovered that my controller redirects (e.g. $this->redirect(array('action'=>'index')); )were failing, but without generating any errors at all (that I could find).

Eventually I tracked down the cause by just taking the whole controller apart and rebuilding it one step at a time – I was including a component (PhpThumb) in my controller but the component was subsequently being included using App:import within a behaviour.

Setting the ‘admin’ path using $html->link

Note: This post is over a year old and the content may no longer be accurate.

Usually CakePHP can work out when link needs to be within the /admin/ section of your site. Sometimes however it needs a little help. When this happens you need to add 'admin' => true to the list of parameters.

1
2
 
echo $html->link($data['SomeModel']['name'], array( 'controller' => 'some_controller', 'action' => 'index', 'admin' => true));