예제 #1
0
 public function run()
 {
     $sections = Sections::find()->all();
     $str = "";
     foreach ($sections as $sec) {
         $a = Html::tag('a', $sec->title, ['href' => $sec->link]);
         $str .= Html::tag('p', $a);
     }
     return $str;
 }
예제 #2
0
 public function actionProduct($id = null)
 {
     $product = Products::find()->where(['id' => $id])->one();
     $sec = Sections::find(['title'])->where(['id' => $product->section_id])->one();
     $others = Products::find()->orderBy(['date' => SORT_DESC])->where(['section_id' => $product->section_id])->andWhere(['not in', 'id', [$id]])->limit(4)->all();
     $comments = Comments::find()->where(['product_id' => $id])->orderBy(['id' => SORT_DESC])->all();
     $model = new CommentForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $com = new Comments();
         $com->product_id = $id;
         $com->login = Yii::$app->session->get('login');
         $com->comment = $model->comment;
         $com->save();
         return $this->redirect(Yii::$app->request->referrer);
     }
     return $this->render('product', ['product' => $product, 'section_title' => $sec, 'others' => $others, 'model' => $model, 'comments' => $comments]);
 }