示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array   $params
  * @param integer $pageSize  The number of results to be displayed per page.
  * @param boolean $published Whether or not testimonials have to be published.
  *
  * @return ActiveDataProvider
  */
 public function search($params, $pageSize = 3)
 {
     $query = Testimonial::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => $pageSize]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
示例#2
0
 /**
  * Finds the Testimonial model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * 
  * @param integer  $id
  * @return Testimonial The loaded model.
  * 
  * @throws NotFoundHttpException if the model cannot be found.
  */
 public function findModel($id)
 {
     if (($model = Testimonial::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Deletes an existing Testimonial model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * 
  * @param  integer $id
  * @return mixed
  *
  * @throws NotFoundHttpException
  */
 public function actionDelete($id)
 {
     $testModel = new Testimonial();
     $testModel->findModel($id)->delete();
     return $this->redirect('admin');
 }