Exemplo n.º 1
0
 /**
  * @param $id
  * @return Response
  */
 public function actionQuestionFavorite($id)
 {
     /** @var Question $model */
     $model = Question::find()->with('favorite')->where(['id' => $id])->one();
     $response = ['data' => ['status' => false], 'format' => 'json'];
     if ($model && ($status = $model->toggleFavorite())) {
         $response['data']['status'] = $status;
         $response['data']['html'] = $this->renderPartial('parts/favorite', compact('model'));
     }
     if (Yii::$app->request->isAjax) {
         return new Response($response);
     }
     return $this->redirect(['view', 'id' => $id]);
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $models = Question::find()->published()->views($this->views)->limit($this->limit)->all();
     return $this->render('popular', ['models' => $models]);
 }