Wednesday, February 4, 2009

Re: Dynamically remove a helper in a controller

That worked a treat!

This is the code i used

$i = array_search('UnwantedHelper', $this->helpers);
unset($this->helpers[$i]);

Thanks

On Feb 4, 12:51 pm, grigri <j...@hendersonwebdesign.com> wrote:
> Remove it from the $helpers member variable in the controller's
> `beforeFilter` method:
>
> class WhateverController extends AppController {
>   function beforeFilter() {
>     foreach($this->helpers as $k => $v) {
>       $helper = is_int($k) ? $v : $k;
>       if ($helper == 'Unwanted') {
>         unset($this->helpers[$k]);
>         break;
>       }
>     }
>     return parent::beforeFilter();
>   }
>
> }
>
> hth
> grigri
>
> On Feb 4, 11:26 am, maxmil <max...@gmail.com> wrote:
>
> > I have a situation where i want a certain helper included in all of my
> > controllers except one.
>
> > I would like to be able to put the helper in my app_controller and
> > explicitly remove it from the one controller that doesn't use it
> > rather than having to manually add it to all but one of my
> > controllers.
>
> > The $helper property of each controller is an array of strings not
> > objects removing the helper from there does not work.
>
> > Does anyone know the right way to do it?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: