On Feb 20, 5:29 am, tompouce <[EMAIL PROTECTED]> wrote:
> Hi!
>
> A year ago I coded an app with cakephp, and in my elements
> I was using this syntax:
>
> $bleh = new Modelname;
>
> for using stuff from the dabatase Modelnames.
>
> But now its not working anymore because I must be missing something, any
> ideas?
>
> Like if i want to include a sidebar to a website.
>
> I include the element Sidebar who get the Bloc from the database Blocs.
>
> like $Sidebar = new Blocs;
>
> foreach ($Blocs as $Bloc): etc...
>
> Thanks!
> --
> View this message in 
> context:http://www.nabble.com/using-models-in-elements-tf3256640.html#a9054292
> Sent from the CakePHP mailing list archive at Nabble.com.

Hi Tom,

There is a way to instanciate a model wherever you need it, but you
should /never/ do that in a view/layout/element. My suggestion would
be to add var $uses = array('Bloc') to your app controller and put the
logic you want in the beforeRender method (but be aware that for a
cake error message an instance of the app controller is used and no
models are loaded). There are other ways, but explaining them might
encourage you to leave the model stuff in the element, which I don't
want to do :)

HTH,

AD


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to