/** * Updates an existing Product model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $this->checkLogin(); $this->layout = 'admin'; $model = $this->findModel($id); $modelType = new Type(); $allType = $modelType->getAllType(); if ($model->load(Yii::$app->request->post())) { $model->image = UploadedFile::getInstances($model, 'image'); foreach ($model->image as $file) { $file->saveAs('images/' . $file->baseName . '.' . $file->extension); $images[] = $file->baseName . '.' . $file->extension; } $model->image = implode(',', $images); $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'allType' => $allType]); } }
<?php use yii\helpers\Html; use yii\bootstrap\Nav; use yii\bootstrap\NavBar; use yii\widgets\Breadcrumbs; use app\assets\AppAsset; use app\models\Type; use yii\helpers\Url; //Create Menu $modelType = new Type(); $types = $modelType->getAllType(); $itemsMenu = [['label' => 'Trang chủ', 'url' => ['/site/index']]]; foreach ($types as $type) { array_push($itemsMenu, ['label' => $type['name'], 'url' => ['/site/type?id=' . $type['id']]]); } array_push($itemsMenu, ['label' => 'Giới thiệu', 'url' => ['/site/#']], ['label' => 'Liên hệ', 'url' => ['/site/#']]); /* @var $this \yii\web\View */ /* @var $content string */ AppAsset::register($this); $this->beginPage(); ?> <!DOCTYPE html> <html lang="<?php echo Yii::$app->language; ?> "> <head> <meta charset="<?php echo Yii::$app->charset; ?>