public function getParentCat() { $cat = AnCats::findOne(['id' => $this->id]); $this->parentCat = $cat->parents(1)->one(); }
/* @var $searchModel vov\announcement\backend\models\AnCatsSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'An Cats'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="an-cats-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create An Cats', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', ['label' => 'parentCat', 'attribute' => 'parentCat', 'value' => function ($searchModel) { $cat = \vov\announcement\backend\models\AnCats::findOne(['id' => $searchModel->id]); $parentCat = $cat->parents(1)->one(); return $parentCat->name; }, 'filter' => yii\Helpers\ArrayHelper::map($searchModel->getParents(), 'id', 'name')], ['label' => 'local', 'attribute' => 'local', 'value' => 'local', 'filter' => \vov\announcement\common\helpers\NeccFunctions::getLanguages()], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
/** * Finds the AnCats model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return AnCats the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = AnCats::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }