public function actionCreate()
{
$model=new Slider;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Slider']))
{
$model->attributes=$_POST['Slider'];
$model->img_url=CUploadedFile::getInstance($model,'img_url');
if($model->save())
$model->img_url->saveAs(Yii::setPathOfAlias('webroot', '/var/www/uploads'));
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
Имя изображения в БД пишется, а вот загрузку не осилю, пишет “move_uploaded_file(): Filename cannot be empty”
Столкнулся с другой проблемой, валидация не работает, т.е. пишу в модели
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('img_url', 'file', 'allowEmpty'=>true, 'types'=>'jpg'),
array('img_url', 'required'),
array('img_url', 'safe'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, img_url', 'safe', 'on'=>'search'),
);
}
Почти допилил, подскажите пожалуйста следующий момент, есть 2 таблицы - Product и ProductImg, все отлично работает, но названия пишутся в обе таблицы, а должны писаться только в таблицу ProductImg, собственно сам код:
$model->img_url = CUploadedFile::getInstance($model, 'img_url');
}
if ($model->img_url !== null && $model->validate(array('img_url')))
{
$model->img_url->saveAs(Yii::app()->getBasePath()."../../../uploads/product/".$model->img_url);
//$model->file_name = $model->img_url;
// save picture name
if( $model->save())
{