I am not sure if there is an alternative; but to me overlading the constructor sounds perfectly fine. I would be interested in hearing reasons why not to. I did see the comment posted in the bug and I personally disagree with the comment:
"2) Do not override model constructors." I would think there is a good reason why not to do that since that was the response to your issue. It would be interesting to get more details and not simply say "Don't do it". I am glad you figured it out. Regards, Alfredo On Mon, Mar 16, 2009 at 3:12 PM, yaman666 <yaman...@gmail.com> wrote: > > Well, that's exactly what I have. However, how to populate that > property from database automatically during model creation without > overloading __construct() is what the question is. > > P.S. I actually figured out that the reason for exceptions was missing > parameters in constructor, so now it works, but still interested to > see if there's an alternative solution. > > On Mar 16, 1:50 pm, Alfredo Quiroga-Villamil <laww...@gmail.com> > wrote: >> I haven't tried this; but try it and see what happens. >> >> 1- Create app/models/app_model.php >> 2- In there you can have >> >> classAppModelextends Model { >> >> protected $sYourPropery = 'property'; >> >> } // End ofAppModel{} >> >> All models that extendAppModelshould now have access to >> $sYourProperty. In one of your models for example try the following: >> >> public function testing() { >> return $this->sYourProperty; >> >> } // End of testing() >> >> and call it from the controller. >> >> Hope that helps. >> >> Regards, >> >> Alfredo >> $this->Model-> >> >> On Mon, Mar 16, 2009 at 2:01 PM, yaman666 <yaman...@gmail.com> wrote: >> >> > Most of my models have an additional property that I was trying to >> > preload by overloadingAppModelconstructor. >> >> > classAppModelextends Model >> > public function __construct() { >> > parent::__construct(); >> > // Load custom property from database and unserialize >> > value >> > } >> > public function beforeSave() { >> > // Serialize and save custom property to database >> > } >> > } >> >> > That broke cakephp when using hasAndBelongsToMany. I filed a bug >> > report (https://trac.cakephp.org/ticket/6194) but was told that I >> > shouldn't be overloadingAppModel. >> >> > Can anyone suggest another simple way to accomplish what I want >> > without having to write each time $model->initialize(); to preload the >> > custom property for all the models? >> >> > Thanks! > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---