Re: Problem with created date; It is not automatically saving to db
Thanks a lot its working now :-) On 6/22/07, Grant Cox <[EMAIL PROTECTED]> wrote: > > > Well, the inbuilt behaviour is hard-coded to "created", "modified" and > "updated". However, you can easily throw a beforeSave() in your > model, check if an id is already set (indicating UPDATE rather than > INSERT) and set your data yourself. > > function beforeSave() > { > if ( empty($this->id) and > empty($this->data[$this->name]['id']) ){ > // inserting a new row > $this->data[$this->name]['TBP_Created_Dt'] = > date('Y-m-d H:i:s'); > } > $this->data[$this->name]['TBP_Modified_Dt'] = date('Y-m-d > H:i:s'); > return parent::beforeSave(); > } > > This can go in a single model, or in your AppModel to apply to all. > > > > > -- Thanks & Regards Sridhar Kuppalli Bangalore [EMAIL PROTECTED] "Behind Every Great Fortune There is a Crime" --~--~-~--~~~---~--~~ 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: Problem with created date; It is not automatically saving to db
Well, the inbuilt behaviour is hard-coded to "created", "modified" and "updated". However, you can easily throw a beforeSave() in your model, check if an id is already set (indicating UPDATE rather than INSERT) and set your data yourself. function beforeSave() { if ( empty($this->id) and empty($this->data[$this->name]['id']) ){ // inserting a new row $this->data[$this->name]['TBP_Created_Dt'] = date('Y-m-d H:i:s'); } $this->data[$this->name]['TBP_Modified_Dt'] = date('Y-m-d H:i:s'); return parent::beforeSave(); } This can go in a single model, or in your AppModel to apply to all. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem with created date; It is not automatically saving to db
Dear All, As we all know that in any table if we don't have primary key as id we can use our own key as primary by defining the $primaryKey in the Model var $primaryKey= 'TBP_Id'; Is there any other way so that i can change the created, modified filed to my own field. Because in my table i have TBP_Created_Dt and TBP_Modified_Dt for created and modified date. Please help me out --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---