Hi Experts,
I’m able to assign single field each time. but I need to do massive assignment, i’m facing problem with file upload field which needs to be stored in file model(other table). and i need to get the id for that file from file model, then i need to store this file_id in my someModel.this is working fine. but how can i do this with massive assignment in this scenario. when I tried to do this with the following code its not working… getting validation error “fields with * are required”
but I didn’t write any rule for this file field as this file will be stored in file model(other model). after storing this fileModel. i need to get the id for this file and i’ll use this file_id for my someModel.
if (isset($_POST['someModel'])) {
$model->attributes = $_POST['someModel'];
$fileModel->file = CUploadedFile::getInstance($model, 'file');
// If validation successful...
if ($model->validate()) {
// Save fileModel
if ($fileModel->saveImage()) {
// Save the someModel after getting file_id from fileModel
$model->file_id = $fileModel->id;
$model->save();
this is my code which is working fine…for individual field assignments:
if (isset($_POST['someModel'])) {
//$model->attributes = $_POST['someModel'];
$model->name = $_POST['someModel']['name'];
$model->description = $_POST['someModel']['description'];
$model->email = $_POST['someModel']['email'];
$model->misc = $_POST['someModel']['misc'];
$fileModel->file = CUploadedFile::getInstance($model, 'file');
// If validation successful...
if ($model->validate()) {
// Save fileModel
if ($fileModel->saveImage()) {
// Save the someModel after getting file_id from fileModel
$model->file_id = $fileModel->id;
$model->save();
}
can any one pls tell me how to do this
Thanks in advance