Re: Problem with Model::afterSave() callback
Davide Why not just build the path when selecting the record? (afterFind() will do). You do not have to duplicate the record's id in the path column. If you must work around the framework lifecycle, then direct $model- execute('UPDATE blah, blah') calls will work. ~GreyCells On Apr 17, 1:06 pm, Davide [EMAIL PROTECTED] wrote: Davide wrote: ... I'm trying to use the afterSave callback in order to update a field of a just inserted record. I have this code[1]. If I didn't comment the saveField() statement, the browser (FireFox) will complain saying[2]. ... Finally after some logging I found what it is. It's a sort of loopback. If in afterSave I try to update a field, the lifecycle (before, save, after) restart. This until the pages goes to timeout. So actually it's not possible to update a record in the afterSave loopback. In order to solve it, I've moved the saveField() in the controller method after the if($this-Model-save()). Is this a framework bug/feature? Is this an application design mistake? With application I mean my application, not the framework. Will make it sense to be able to specify for example a parameter to the afterSave callback in order to tell to the framework to skip the natuaral save lifecycle? Thanks a lot Bye Davide --~--~-~--~~~---~--~~ 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 Model::afterSave() callback
Davide wrote: ... I'm trying to use the afterSave callback in order to update a field of a just inserted record. I have this code[1]. If I didn't comment the saveField() statement, the browser (FireFox) will complain saying[2]. ... Finally after some logging I found what it is. It's a sort of loopback. If in afterSave I try to update a field, the lifecycle (before, save, after) restart. This until the pages goes to timeout. So actually it's not possible to update a record in the afterSave loopback. In order to solve it, I've moved the saveField() in the controller method after the if($this-Model-save()). Is this a framework bug/feature? Is this an application design mistake? With application I mean my application, not the framework. Will make it sense to be able to specify for example a parameter to the afterSave callback in order to tell to the framework to skip the natuaral save lifecycle? Thanks a lot Bye Davide --~--~-~--~~~---~--~~ 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 Model::afterSave() callback
GreyCells wrote: Why not just build the path when selecting the record? (afterFind() will do). You do not have to duplicate the record's id in the path column. I thought about an additional field, 'cause if I build the path in the afterFind(), I would have to cycle the recordset in order to add the path and then in the view I will have to cycle again the data collection in order to present it. I could even build the path in the view but I would like to reduce at minimum the data manipulation in this part of application. If you must work around the framework lifecycle, then direct $model- execute('UPDATE blah, blah') calls will work. Hmmm i forgot this method :) Thank bye Davide --~--~-~--~~~---~--~~ 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 Model::afterSave() callback
Hello everybody. I'm trying to use the afterSave callback in order to update a field of a just inserted record. I have this code[1]. If I didn't comment the saveField() statement, the browser (FireFox) will complain saying[2]. What could it be? Thanks a lot Davide 1. //controller function add(){ if(isset($this-data)){ if($this-Upload-save($this-data)){ $this-flash(ok,/uploads); return 0; }else{ $this-flash(KO,/uploads); return -1; } } $this-render(add-edit); return 0; } //model function beforeSave(){ parent::beforeSave(); if(isset($this-data)){ $this-data[Upload][name] = $this-data[Upload][file][name]; $this-data[Upload][ctype] = $this-data[Upload][file][type]; } return true; } /** * sets some values after saved */ function afterSave(){ parent::afterSave(); $id = $this-getLastInsertID(); $this-set(id,$id); $this-saveField(path,/uploads/view/ . $id); } 2. /// The connection was reset The connection to the server was reset while the page was loading. * The site could be temporarily unavailable or too busy. Try again in a few moments. * If you are unable to load any pages, check your computer's network connection. * If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---