Allright I understand I've thought about this before too; Usually I just say screw it and if I'm moving the file afterSave (instead of beforeSave) I just assume the function worked properly. I'm assuming you do the move uploaded file in the afterSave() to use the Model ID in the filename? If this is the case, one possible solution I've thought of is to move the uploaded file beforeSave() so you can invalidate() if necessary, and then do a file rename in the afterSave() - you could set up some sort of array with the temporary filename(s) and path(s) and use that in afterSave to do your renaming. I've never done this, but it crossed my mind in a similar situation.
Another solution, which isn't very MVC, would be to perform the move_upload_file in your controller after the model->save() action, and handle the error from there. Unfortunately I don't know of any other way to throw an error from afterSave(), perhaps someone else has a better solution. Here's a "bug" report filed on a similar topic: https://trac.cakephp.org/ticket/1735 On Apr 30, 11:53 am, avairet <[EMAIL PROTECTED]> wrote: > Hi Clark, > > Thank you for answer. > > I don't redirect after find, it's an error in my first post. I would > like to redirect after save! > > I know it's a bad idea to redirect from Model, but I'm looking for a > solution to stop action after a record save, like the return false in > before Save. > > In fact, in my Model::afterSave, I do a "move_uploaded_file()" and if > this move doesn't work, I would like to redirect in the previous > controller action instead of the redirect(index) > > Sorry for my simple English, I hope this message is understandable... > > On 30 avr, 17:46, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > > You shouldn't redirect from a model as a model should only be dealing > > with data, not page logic. > > > You should be doing the redirect in your controller. > > > What are you redirecting for anyway? If you redirect after finding > > data, you'll lose that data and have to find again. > > > On Apr 30, 11:36 am, avairet <[EMAIL PROTECTED]> wrote: > > > > Hi everybody, > > > > Is it possible to redirect from the Model? > > > I would like to redirect in an specific action from "afterFind()" > > > callback... but if I set "return false" in this callback, like it's > > > possible in "beforeSave()", I can't redirect! > > > > Thanks by advance for your ideas. > > > > BR --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---
