Answer the question
In order to leave comments, you need to log in
How to save a record to the database?
public function actionCreate() {
$model = new MyGallery;
if(!empty($_FILES)){
move_uploaded_file($_FILES['file']['tmp_name'],
Yii::app()->request->baseUrl . 'images/upload/' . '13' . $_FILES['file']['name']);
$model->img_url = $_FILES['file']['name'];
};
if (isset($_POST['MyGallery'])) {
$model->attributes = $_POST['MyGallery'];
// $model->img_url = $_FILES['file']['name'];
if ($model->save())
$this->redirect(array('view', 'id' => $model->id));
}
$this->render('create', array(
'model' => $model,
));
}
Answer the question
In order to leave comments, you need to log in
Rearrange, that is, write like this:
public function actionCreate() {
$model = new MyGallery;
if (isset($_POST['MyGallery'])) {
$model->attributes = $_POST['MyGallery'];
if(!empty($_FILES)){
move_uploaded_file($_FILES['file']['tmp_name'],
Yii::app()->request->baseUrl . 'images/upload/' . '13' . $_FILES['file']['name']);
$model->img_url = $_FILES['file']['name'];
};
if ($model->save())
$this->redirect(array('view', 'id' => $model->id));
}
$this->render('create', array(
'model' => $model,
));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question