lrzins 1 Posted June 7, 2013 Report Share Posted June 7, 2013 Hi Larry, on page 216 of your Yii book, you describe how to rename an uploaded file using the $model->id of the User model. I think this is a good idea, but I don't see how your code can work without an afterSave or something. Here is your code: $model->avatar->saveAs($dest . '/' . $model->id . '.' . $model->avatar->extensionName); The line above would have to come after the code to save the model: if ($model->save()) because you don't obtain the $model->id until after you save it. But since you've already saved the file's name to the database, the filename in the database and the name of the uploaded file don't match. And you should'nt save the uploaded file in the file system until you know that the save to the database was successful. Do you see what I mean? Am I missing something? Larry Z. Quote Link to post Share on other sites
Larry 428 Posted June 8, 2013 Report Share Posted June 8, 2013 Yes, you would have to do that after saving the model. That's shown on the previous pages. Sorry it's not more clear. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.