I think you're doing 2 queries now, one for the setup in the controller and
one for the setup in the component.

Follow the tips from Miles and you can share the array from the controller
with the component.

Lesser queries and as a bonus it will be easier to refactor you code
afterwards :)

On Wed, Sep 23, 2009 at 6:36 AM, mig_akira <mig_ak...@hotmail.com> wrote:

>
>
> Well, problem solved...don't know if I did it the right way, though...
>
> Since the variable I was trying to use in my component was an array of data
> from a table, I had to import the model in the component using:
>
>        $Category = ClassRegistry::init('Category');
>
> So I set the array after that, in the component as well, like this:
>
>   $categories = $Category->find('all',array(
>                'conditions'=>array('Category.active'=>1),
>                'order'=> array('Category.index'=>'ASC')
>        ));
>
> Thanks!
>
>
> mig_akira wrote:
> >
> > Hello everyone.
> >
> > I'm trying to build a simple dropdown menu for a website. I'm using this
> > tutorial:
> > http://www.palivoda.eu/2008/04/dynamic-menu-in-cakephp/
> >
> > THe menu is working, but I don't know how can I pass the array with all
> > the data to build the menu from the app_controller to the menu component.
> >
> > I was using a simple element menu, with this in my appcontroller's
> > beforeFilter:
> >
> > function _setLayoutFrontEnd()
> >     {
> >       $this->layout = 'default';
> >         $this->_loadMenu();
> >     }
> >
> >     function _loadMenu()
> >     {
> >               $categories = $this->Category->find('all',array(
> >               'conditions'=>array('Category.ativo'=>1),
> >               'order'=> array('Category.indexpag'=>'ASC')
> >       ));
> >       $this->set('categories',$categories);
> > }
> >
> > With that, I could use the array $categories in my
> view/elements/menu.ctp.
> >
> > Now I need to pass it to my controllers/components/menu.php.
> > How can I do that?
> >
> > Thanks!!!
> >
>
> --
> View this message in context:
> http://www.nabble.com/how-can-I-pass-variable-from-app_controller-to-a-component--tp25530525p25530987.html
> Sent from the CakePHP mailing list archive at Nabble.com.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to