все могут помочь мне, пожалуйста? я хочу, чтобы моя система вставляла новую запись, когда я обновляю ее в рамках yii
public function actionUpdate($id)<br/>
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Entrydata']))
{
$_POST['Entrydata']['photo'] = $model->photo;
$model->attributes=$_POST['Entrydata'];
$uploadedFile = CUploadedFile::getInstance($model,'photo');
if($model->save())
{
if(!empty($uploadedFile)) // check if uploaded file is set or not
{
$uploadedFile->saveAs(Yii::app()->basePath.'/../images/'.$model->photo); // image will uplode to rootDirectory/banner/
}
$this->redirect(array('view','id'=>$model->id_entry));
}}
$this->render('create',array(
'model'=>$model,
));
}
Сбросить атрибут перед сохранением.
$model->unsetAttributes(array("id_entry"));
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Entrydata']))
{
$_POST['Entrydata']['photo'] = $model->photo;
$model->attributes=$_POST['Entrydata'];
$uploadedFile = CUploadedFile::getInstance($model,'photo');
// Unset Primary Key value.
$model->unsetAttributes(array("id_entry"));
if($model->save())
{
if(!empty($uploadedFile)) // check if uploaded file is set or not
{
$uploadedFile->saveAs(Yii::app()->basePath.'/../images/'.$model->photo); // image will uplode to rootDirectory/banner/
}
$this->redirect(array('view','id'=>$model->id_entry));
}}
$this->render('create',array(
'model'=>$model,
));
}
Других решений пока нет …