Exemplo n.º 1
0
 public function actionIndex($id = null)
 {
     $model = $id === null ? new Product() : $this->findModel($id);
     if (!empty($model->details)) {
         $model->titleVi = $model->details[0]->title;
         $model->titleEn = $model->details[1]->title;
         $model->thumbnailVi = $model->details[0]->thumbnail;
         $model->thumbnailEn = $model->details[1]->thumbnail;
         $model->summaryVi = $model->details[0]->summary;
         $model->summaryEn = $model->details[1]->summary;
         $model->contentVi = $model->details[0]->content;
         $model->contentEn = $model->details[1]->content;
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         $listItem = Product::find()->with('details')->all();
         $category = Category::find()->with('details')->all();
         $listCate = [];
         foreach ($category as $cate) {
             $listCate[$cate->id] = $cate->details[0]->title . ' / ' . $cate->details[1]->title;
         }
         return $this->render('index', ['model' => $model, 'listItem' => $listItem, 'listCate' => $listCate]);
     }
 }
Exemplo n.º 2
0
 public function actionIndex($id = null)
 {
     $model = $id === null ? new Category() : $this->findModel($id);
     if (!empty($model->details)) {
         $model->titleVi = $model->details[0]->title;
         $model->titleEn = $model->details[1]->title;
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         $listItem = Category::find()->with('details')->all();
         return $this->render('index', ['model' => $model, 'listItem' => $listItem]);
     }
 }