I have 2 tables like this :
table artist
id int Primary Key,
artistname;
table song
id in Primary Key,
artist_id int Foreign Key,
filesong varchar;
I write in songcontroller like this :
public function actionCreate()
{
$model=new Song;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Song']))
{
$model->attributes=$_POST['Song'];
$uploadedFile=CUploadedFile::getInstance($model,'filesong');
$fileName = "{$uploadedFile}"; // file name
$model->filesong = $fileName;
if($model->save())
if(isset($fileName) && count($fileName) > 0)
{
foreach ($fileName as $i=>$ii)
{
if ($ii->saveAs(Yii::getPathOfAlias('webroot').'/storage/'.$ii->name))
{
$file_add = new Song();
$file_add->filesong = $ii->name;
$file_add->save();
}
else
$file_add = new Song();
$file_add->filesong = $ii->name;
$file_add->save();
if($model->save())
{
$this->redirect(array(‘view’,'id'=>$model->id));
}
}
}
}
$this->render('create',array(
'model'=>$model,
));
}
it doesn’t work at all … ;(
How to use CMultiFileUpload ?so I can insert table song with dynamic upload …help me, please