Exemple #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posting::find()->where(['status' => 1]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /**
      * Setup your sorting attributes
      * Note: This is setup before the $this->load($params) 
      * statement below
      */
     $dataProvider->setSort(['attributes' => ['parent_id', 'ParentsName' => ['asc' => ['fr001.parent' => SORT_ASC], 'desc' => ['fr001.parent' => SORT_DESC], 'label' => 'Parent Name']]]);
     if (!($this->load($params) && $this->validate())) {
         /**
          * The following line will allow eager loading with country data 
          * to enable sorting by country on initial loading of the grid.
          */
         $query->joinWith(['parents']);
         return $dataProvider;
     }
     /* Add your filtering criteria */
     // filter by parent name
     $query->joinWith(['parents' => function ($q) {
         $q->where('fr001.parent LIKE "%' . $this->ParentsName . '%"');
     }]);
     return $dataProvider;
 }
 /**
  * Finds the Posting model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Posting the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Posting::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }