How Make Dynamic One To Many with ext. TbFileUpload… This my code :
view code :
<?php
$this->widget( 'bootstrap.widgets.TbFileUpload', array(
'url' => Yii::app( )->createUrl( "/storage/Upload"),
'model' => $model,
//We set this for the widget to be able to target our own form
'htmlOptions' => array('id'=>'storage-form'),
'attribute' => 'filesong',
'multiple' => true,
'options' => array(
'acceptFileTypes' => 'js:/(\.|\/)(mp3|mpeg|wma)$/i',
) )
);
?>
Code Controller :
public function actionUpload( )
{
header('Vary: Accept');
if (isset($_SERVER['HTTP_ACCEPT']) &&
(strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false))
{
header('Content-type: application/json');
} else {
header('Content-type: text/plain');
}
$data = array();
$model = new Storage('upload');
$model->filesong = CUploadedFile::getInstance($model, 'filesong');
if ($model->filesong !== null && $model->validate(array('filesong')))
{
$handle = new Upload($model->filesong);
if ($handle->uploaded)
$handle->process(Yii::app()->getBasePath().'/storage/tmp/');
if($model->model()->save())
{
// return data to the fileuploader
$data[] = array(
'name' => $model->filesong->name,
'type' => $model->filesong->type,
'size' => $model->filesong->size,
'delete_url' => $this->createUrl('storage/delete',
array('id' => $model->id, 'method' => 'uploader')),
'delete_type' => 'POST');
} else {
$data[] = array('error' => 'Unable to save model after saving filesong');
}
} else {
if ($model->hasErrors('filesong'))
{
$data[] = array('error', $model->getErrors('filesong'));
} else {
throw new CHttpException(500, "Could not upload file ". CHtml::errorSummary($model));
}
}
// JQuery File Upload expects JSON data
echo json_encode($data);
}
these all my code can insert id(int),song_id(int) but filesong(varchar) couldn’t insert into database and the files couldn’t save to the folder storage…
it should TbFileUpload view like this
3937
but it couldn’t view like that.
please help me to use TbFileUpload in good way…Thanks In Advance
PS : Sorry with my English