/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Child::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']]]); 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; }
public function actionGetChild() { $out = []; if (isset($_POST['depdrop_parents'])) { $parents = $_POST['depdrop_parents']; if ($parents != null) { $cat_id = $parents[0]; $model = Child::find()->asArray()->where(['PARENT_ID' => $cat_id])->all(); foreach ($model as $key => $value) { $out[] = ['id' => $value['CHILD_ID'], 'name' => $value['CHILD_NAME']]; } echo json_encode(['output' => $out, 'selected' => '']); return; } } echo Json::encode(['output' => '', 'selected' => '']); }
/** * Finds the Child model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Child the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Child::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }