Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Grandchild::find();
     $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'], 'ChildName' => ['asc' => ['fr000.CHILD_NAME' => SORT_ASC], 'desc' => ['fr000.CHILD_NAME' => SORT_DESC], 'label' => 'Child 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']);
         $query->joinWith(['child']);
         return $dataProvider;
     }
     /* Add your filtering criteria */
     // filter by parent name
     $query->joinWith(['parents' => function ($q) {
         $q->where('fr001.parent LIKE "%' . $this->ParentsName . '%"');
     }]);
     return $dataProvider;
 }
 public function actionGetGrandchild()
 {
     $out = [];
     if (isset($_POST['depdrop_parents'])) {
         $ids = $_POST['depdrop_parents'];
         //  $cat_id =7;
         // $subcat_id =4;
         $cat_id = $ids[0];
         $subcat_id = $ids[1];
         if ($cat_id != null) {
             // $data = Grandchild::getProdList($cat_id, $subcat_id);
             //    $model = Grandchild::find()->asArray()->where(['CHILD_ID'=>$subcat_id,'PARENT_ID'=>$cat_id])->all();
             $model = Grandchild::find()->asArray()->where(['CHILD_ID' => $cat_id, 'PARENT_ID' => $subcat_id])->all();
             foreach ($model as $key => $value) {
                 $out[] = ['id' => $value['GRANDCHILD_ID'], 'name' => $value['GRANDCHILD']];
             }
             echo json_encode(['output' => $out, 'selected' => '']);
             return;
         }
     }
     echo Json::encode(['output' => '', 'selected' => '']);
 }
 /**
  * Finds the Grandchild model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Grandchild the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Grandchild::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }