RE: Model not available from app_controller
Oh wait I've just realized that we are discussing this issue over a thread that is not related. Please move this topic to a new thread. -MI --- Remember, smart coders answer ten questions for every question they ask. So be smart, be cool, and share your knowledge. BAKE ON! -Mensaje original- De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre de Steniskis Enviado el: Viernes, 08 de Diciembre de 2006 06:59 a.m. Para: Cake PHP Asunto: Re: Model not available from app_controller Hi Mariano, Thank you for your help but in fact all works except one page and to be precise the error displayed is about this line in the head helper $this->_register(array($file,'css',$htmlAttributes)); This error masks something else... Sten --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Hi, Eventually I found a problem on a table name in one of my models. I think there was two problems with a difficulty to identify the errors. Thanks for your help Sten --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Hi Mariano, Thank you for your help but in fact all works except one page and to be precise the error displayed is about this line in the head helper $this->_register(array($file,'css',$htmlAttributes)); This error masks something else... Sten --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Is CSS a helper you built? If so, aren't you missing the $ ? If you are trying to link to a CSS file in your then do: css('css_file'); ?> Where css_file is a reference to WEBROOT/css/css_file.css -MI --- Remember, smart coders answer ten questions for every question they ask. So be smart, be cool, and share your knowledge. BAKE ON! -Mensaje original- De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre de Steniskis Enviado el: Viernes, 08 de Diciembre de 2006 05:39 a.m. Para: Cake PHP Asunto: Re: Model not available from app_controller It is a problem with the head helper. So I put all my helpers in my app_controller and then there is an error message about css->register(). May be someone could have an insight on this problem of missing. I feel like turning around and around. Thank you for your help --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Hello Thank you AD7six for your insight, happy for you Langdon. I did what you suggest AD7six, it was fine for my app_controller but now I have this message "Call to a member function on a non-object in /var/www/html/SID/app/views/layouts/default.thtml" It is a problem with the head helper. So I put all my helpers in my app_controller and then there is an error message about css->register(). May be someone could have an insight on this problem of missing. I feel like turning around and around. Thank you for your help Sten --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Hi AD7six Thank you for this info you have solved my problem. It turns out that I had missed uploading a table associated with the last round of changes to implement an advertising block. As you pointed out, the "table missing" error was being masked by the fact that the model wasn't available in appController beforeFilter(). All very convoluted! However, wrapping all of my beforeFilter() code that used models with: if (low($this->name) > != 'app') { code that accesses models here ... } did the trick and I was able to see the right error. In the future I will do this with all appController code that requires access to model data. I think I will also spend some time today working out how to use Ant to upload database changes to avoid this problem. I am loving using Ant to build to dev, staging, and production servers. It is a powerful tool. Thank you once again to everyone who has contributed to this discussion. It is a hallmark of how strong the Cake community is that you have helped me overcome a serious (if simple) problem so quickly. The Cake framework and your support is greatly appreciated. Regards, Langdon > Hi All, > > It used to be true that if you declare $uses in your app controller, > you would lose the automatic "This controller has a model of the same > name unless you tell me otherwise" logic in child classes, but this > change means that it isn't true anymore: > https://trac.cakephp.org/changeset/4012/branches/1.1.x.x/cake/libs/controller/controller.php > > IIRC another consequence use to be that you could invoke a loop if > anything related to the models in your app controller were not correct > - but if that ever was the case, it certainly isn´t true anymore it > seems. > > Irgo it seems that with a recent cake version, declaring $uses in your > app controller doesn´t cause any problems whatsoever. > > WRT the OP, it's probably worth bearing this in mind: > If an error is triggered, an instance of the app_controller is used - > but models are not loaded. It would be wise to put if (low($this->name) > != 'app') {} around the use of this model to allow you to avoid it > being run for (missing connection, missing model) errors. > > HTH, > > AD7six --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Oh well. Ok got it. Thanks Larry for clearing it out. :) -MI --- Remember, smart coders answer ten questions for every question they ask. So be smart, be cool, and share your knowledge. BAKE ON! De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre de Larry E. Masters aka PhpNut Enviado el: Jueves, 07 de Diciembre de 2006 02:52 p.m. Para: cake-php@googlegroups.com Asunto: Re: Model not available from app_controller Components should be used by a controller to alter data the controller sends to it, not interact directly with the models. --~--~-~--~~~---~--~~ 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: Model not available from app_controller
> That's what I was basing on, and the post that I linked where you can see > for example Larry recommending to take out $uses in AppController. The reason I recommended not using var $uses in the AppController in prior releases of cake was you would have to redefine it in all child classes. With the current release this is no longer an issue, the child class will "inherit" the $uses from AppContorller without overwriting the child classes $uses or if you have not defined $uses it will expect the Model related to the child class. I still believe it is better to make a component when a model is to be used > from AppController. I want AppController to deal with stuff that is > general > to all controllers, and when that stuff involves model interaction I > prefer > to use components. Components should be used by a controller to alter data the controller sends to it, not interact directly with the models. -- /** * @author Larry E. Masters * @var string $userName * @param string $realName * @returns string aka PhpNut * @access public */ --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Also more on this issue: lots of people need model logic on AppController but they don't really need the used models to be available on all controllers, which is what happens if you add it to $uses on AppControler. On Dec 7, 5:04 am, "gwoo" <[EMAIL PROTECTED]> wrote: > I dont know who recommends not using models in AppController, nor do i > know who recommends using models in components. In fact, I would do the > exact opposite. You create too many dependencies when you try to put a > model in a component. Components should be interchangeable between apps > without any need to worry about a model. > > Its possible that the production site needs to have the cache cleared. --~--~-~--~~~---~--~~ 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: Model not available from app_controller
That's what I was basing on, and the post that I linked where you can see for example Larry recommending to take out $uses in AppController. I still believe it is better to make a component when a model is to be used from AppController. I want AppController to deal with stuff that is general to all controllers, and when that stuff involves model interaction I prefer to use components. -MI --- Remember, smart coders answer ten questions for every question they ask. So be smart, be cool, and share your knowledge. BAKE ON! -Mensaje original- De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre de AD7six Enviado el: Jueves, 07 de Diciembre de 2006 08:12 a.m. Para: Cake PHP Asunto: Re: Model not available from app_controller On Dec 7, 8:35 am, "Mariano Iglesias" <[EMAIL PROTECTED]> wrote: > You should not use models from your AppController. If you need model logic > set it as a component and use the component from AppController. > > Check this post: > > http://groups-beta.google.com/group/cake-php/browse_thread/thread/179... > 8b7276/e2767af2ee5ce498?lnk=gst&q=&rnum=21#e2767af2ee5ce498 > Hi All, It used to be true that if you declare $uses in your app controller, you would lose the automatic "This controller has a model of the same name unless you tell me otherwise" logic in child classes, but this change means that it isn't true anymore: https://trac.cakephp.org/changeset/4012/branches/1.1.x.x/cake/libs/controlle r/controller.php IIRC another consequence use to be that you could invoke a loop if anything related to the models in your app controller were not correct - but if that ever was the case, it certainly isn´t true anymore it seems. Irgo it seems that with a recent cake version, declaring $uses in your app controller doesn´t cause any problems whatsoever. WRT the OP, it's probably worth bearing this in mind: If an error is triggered, an instance of the app_controller is used - but models are not loaded. It would be wise to put if (low($this->name) != 'app') {} around the use of this model to allow you to avoid it being run for (missing connection, missing model) errors. --~--~-~--~~~---~--~~ 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: Model not available from app_controller
This last operation did no change. Sten --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Hi all of you, Thank you for your explanations and you contributions to this debate. I think I will separate my model in two ones on the same table, I think this will fix this problem. Sten --~--~-~--~~~---~--~~ 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: Model not available from app_controller
On Dec 7, 9:49 am, Langdon Stevenson <[EMAIL PROTECTED]> wrote: > When I run the same code on the production server I get: > > appcontroller Object > ( > [_log] => > [name] => app See my previous message ;). HTH, AD7six Please note: The manual/bakery is a good place to start any quest for info. The cake search (at the time of writing) erroneously reports less/no results for the google group. The wiki may contain incorrect info - read at your own risk (it's mainly user submitted) :) You may get your answer quicker by asking on the IRC Channel (you can access it with just a browser here:http://irc.cakephp.org). --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Hi Gwoo > I dont know who recommends not using models in AppController, nor do i > know who recommends using models in components. In fact, I would do the > exact opposite. You create too many dependencies when you try to put a > model in a component. Components should be interchangeable between apps > without any need to worry about a model. > > Its possible that the production site needs to have the cache cleared. I thought this might be the case too, so have tried deleting all contents in cache folder. I have even deleted the entire project and reloaded it (built from the main branch of the project on my Perforce server, so there can be no cache files hanging around from the dev server), but no change. Regards, Langdon --~--~-~--~~~---~--~~ 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: Model not available from app_controller
On Dec 7, 8:35 am, "Mariano Iglesias" <[EMAIL PROTECTED]> wrote: > You should not use models from your AppController. If you need model logic > set it as a component and use the component from AppController. > > Check this post: > > http://groups-beta.google.com/group/cake-php/browse_thread/thread/179... > 8b7276/e2767af2ee5ce498?lnk=gst&q=&rnum=21#e2767af2ee5ce498 > Hi All, It used to be true that if you declare $uses in your app controller, you would lose the automatic "This controller has a model of the same name unless you tell me otherwise" logic in child classes, but this change means that it isn't true anymore: https://trac.cakephp.org/changeset/4012/branches/1.1.x.x/cake/libs/controller/controller.php IIRC another consequence use to be that you could invoke a loop if anything related to the models in your app controller were not correct - but if that ever was the case, it certainly isn´t true anymore it seems. Irgo it seems that with a recent cake version, declaring $uses in your app controller doesn´t cause any problems whatsoever. WRT the OP, it's probably worth bearing this in mind: If an error is triggered, an instance of the app_controller is used - but models are not loaded. It would be wise to put if (low($this->name) != 'app') {} around the use of this model to allow you to avoid it being run for (missing connection, missing model) errors. HTH, AD7six Please note: The manual/bakery is a good place to start any quest for info. The cake search (at the time of writing) erroneously reports less/no results for the google group. The wiki may contain incorrect info - read at your own risk (it's mainly user submitted) :) You may get your answer quicker by asking on the IRC Channel (you can access it with just a browser here:http://irc.cakephp.org). --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Hi Langdon, Thank you for this question, I have exactly the same problem. I use it for a menu for every page. It works with most controllers, but not with a particular one. I can't see anay difference with this one but I have "Call to a member function on a non-object" on this line $this->lesmenus=$this->MenuPage->exposer(); exposer() is method inside the model MenuPage. Thank you Sten --~--~-~--~~~---~--~~ 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: Model not available from app_controller
Hi Mariano Thanks for the suggestion > You should not use models from your AppController. If you need model > logic set it as a component and use the component from AppController. I will leave this debate to more you and Gwoo! > Check this post: > > http://groups-beta.google.com/group/cake-php/browse_thread/thread/17952262b38b7276/e2767af2ee5ce498?lnk=gst&q=&rnum=21#e2767af2ee5ce498 Thanks, I do remember that one, (hence I have the Setting model set in the child controllers var $uses). > Just to debug that problem do this: > > if (!isset($this->Setting)) { > loadModel(‘Setting’); > $this->Setting =& new Setting(); > } > > $siteStatus = $this->Setting->findByName('site_status'); Done. I now get the following error: Fatal error: Cannot redeclare class setting in /home/justco/www/app/models/setting.php on line 2 Interestingly, when I do: print_r($this); In the beforeFilter in appController on the dev server I get the following output: homecontroller Object ( [_log] => [name] => Home [here] => / [webroot] => / [action] => index [uses] => Array ( [0] => Issue [1] => Article [2] => Setting [3] => Colour [4] => Issue [5] => Advertisement ) [helpers] => Array ( [0] => Html [1] => othAuth ) ... When I run the same code on the production server I get: appcontroller Object ( [_log] => [name] => app [here] => [webroot] => [action] => [uses] => [helpers] => Array ( [0] => Html [1] => othAuth ) ... Unfortunately my understanding of the underlying structure of Cake isn't strong enough to interpret this, but it explains why the Setting model isn't available. Regards, Langdon --~--~-~--~~~---~--~~ 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: Model not available from app_controller
I dont know who recommends not using models in AppController, nor do i know who recommends using models in components. In fact, I would do the exact opposite. You create too many dependencies when you try to put a model in a component. Components should be interchangeable between apps without any need to worry about a model. Its possible that the production site needs to have the cache cleared. --~--~-~--~~~---~--~~ 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: Model not available from app_controller
You should not use models from your AppController. If you need model logic set it as a component and use the component from AppController. Check this post: http://groups-beta.google.com/group/cake-php/browse_thread/thread/17952262b3 8b7276/e2767af2ee5ce498?lnk=gst&q=&rnum=21#e2767af2ee5ce498 Just to debug that problem do this: if (!isset($this->Setting)) { loadModel('Setting'); $this->Setting =& new Setting(); } $siteStatus = $this->Setting->findByName('site_status'); But again, it is strongly recommended that you don't use models at AppController. -MI --- Remember, smart coders answer ten questions for every question they ask. So be smart, be cool, and share your knowledge. BAKE ON! -Mensaje original- De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre de Langdon Stevenson Enviado el: Jueves, 07 de Diciembre de 2006 03:44 a.m. Para: cake-php@googlegroups.com Asunto: Model not available from app_controller I have a very strange problem. A site that I have developed has a beforeFilter in app_controller.php that performs a find query on a model (Setting) to do various set-up functions for every page. This is the line of code that is causing the problem: $siteStatus = $this->Setting->findByName('site_status'); --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---