lrzins Posted June 7, 2013 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. Link to comment Share on other sites More sharing options...
Larry Posted June 8, 2013 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. Link to comment Share on other sites More sharing options...
Recommended Posts