Re: using models in elements
Woodsman, The helper grabs the metadata of the model behind-the-scenes. This does not involve access or manipulation of the model data itself, it simply introspects static data about the model. Subtle difference. On Feb 21, 3:05 pm, the_woodsman [EMAIL PROTECTED] wrote: Ad7six, Thans for your input, but to be honest i'm still confused! To quote from that link you posted: In Cake 1.2, we're transitioning to an approach to form building that is more directly model-oriented, and according to the API, the first parameter to FormHelper::create() is actually supposed to be the name of a model, i.e.: ?=$form-create('Task', array('default' = false)); ? However, if you don't provide one, it is assumed to be the default model for the controller (in this case TasksController). If this doesn't look at the Model in any way, why would you need the name of the model?!? Surely there's nothing in $data to use ot guess what kind of form field to use... I'm sure once i switch to 1.2 It'll all become clear! Woody On Feb 21, 7:52 am, AD7six [EMAIL PROTECTED] wrote: On Feb 21, 2:02 am, the_woodsman [EMAIL PROTECTED] wrote: I'm confused about this issue. I had assumed having Models referenced directly in presentation related code was bad practice - but isn't that the Cake 1.2 way of doing form inputs? HiWoodsman, The methods which are used to generate form inputs have been modified in 1.2 but the MVC concepts certainly havent. See here for some examples, note the references to $data, and nothing at all do with instanciating and using a model.http://cake.insertdesignhere.com/posts/view/15 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 cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: using models in elements
On Feb 21, 9:05 pm, the_woodsman [EMAIL PROTECTED] wrote: Ad7six, Thans for your input, but to be honest i'm still confused! To quote from that link you posted: In Cake 1.2, we're transitioning to an approach to form building that is more directly model-oriented, and according to the API, the first parameter to FormHelper::create() is actually supposed to be the name of a model, i.e.: ?=$form-create('Task', array('default' = false)); ? However, if you don't provide one, it is assumed to be the default model for the controller (in this case TasksController). If this doesn't look at the Model in any way, why would you need the name of the model?!? Surely there's nothing in $data to use ot guess what kind of form field to use... I'm sure once i switch to 1.2 It'll all become clear! Woody Hi Woody Try this: put the following in any form view file (use the blog tutorial if nothing else): pr ($data); look for the name of a model and the name of a field, especially after submitting a form with something missing (i.e. using the blog tutorial and tryihng to create an empty post) Note that a model INSTANCE is nowhere visible or accessible the model NAME is but that is just data. 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 cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: using models in elements
I'm confused about this issue. I had assumed having Models referenced directly in presentation related code was bad practice - but isn't that the Cake 1.2 way of doing form inputs? It seems to make for cleaner and simpler code that way... tompouce, is there a chance your new problems are caused by the lazy loading feature, introduced not too long ago? The post Component can't create a model discusses similar issues,and mentions the loadModel function... http://groups.google.com/group/cake-php/browse_thread/thread/71d9021c27f32419/8a6d98c57a59609f?lnk=gstq=create+modelrnum=3hl=en#8a6d98c57a59609f On Feb 20, 2:45 pm, tompouce [EMAIL PROTECTED] wrote: Yeah but, I want just to include an element that will get my blocks for my sidebar from the database Blocks without any thing more than a model, like i used to do... is there a good simple way to this? Thanks! AD7six wrote: 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 -- View this message in context:http://www.nabble.com/using-models-in-elements-tf3256640.html#a9063042 Sent from the CakePHP mailing list archive at Nabble.com. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
using models in elements
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. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: using models in elements
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 cake-php@googlegroups.com 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 -~--~~~~--~~--~--~---