I'm trying to upload four images and it saves on the server but not in DB. Dont know why but the image attribute dont receive the value from variable.
Controller action:
Print "dados" and "attributes":
Controller action:
if(isset($_POST['Noticias'])) { $dados=$_POST['Noticias']; unset($dados['fotos']); $fotos = CUploadedFile::getInstancesByName('Noticias'); if(isset($fotos) && count($fotos) > 0) { foreach($fotos as $c => $foto) { $nome_foto = $foto->name; $nome_foto = explode('.',$nome_foto); $nome_foto = time().uniqid().'.'.$nome_foto[1]; if($foto->saveAs(Yii::getPathOfAlias('webroot').'/arquivos/fotos/noticias/' . $nome_foto)) { $c++; $dados['foto' . $c] = $nome_foto; }else { throw new CException(Yii::t('yii','Erro ao fazer upload do arquivo "{nome}".', array('{nome}'=>$nome_foto))); } } } $model->attributes = $dados; print_r($dados); print_r("<br/><br/>"); print_r($model->attributes); die(); if($model->save()) $this->redirect(array('view','id'=>$model->id_noticia)); }
Print "dados" and "attributes":
//Dados Array ( [titulo] => teste [categoria] => 1 [data] => 3 [id_album] => 3 [resumo] => 3 [conteudo] => 3 [fonte] => 3 [legenda1] => [legenda2] => [legenda3] => [legenda4] => [newsletter] => [foto1] => 1360931081511e29098511a.jpg ) //Attributes Array ( [titulo] => teste [categoria] => 1 [data] => 3 [id_album] => 3 [resumo] => 3 [conteudo] => 3 [fonte] => 3 [legenda1] => [legenda2] => [legenda3] => [legenda4] => [newsletter] => [id_noticia] => [foto1] => [foto2] => [foto3] => [foto4] => )