/** * List of grid actions * @return array */ public function actions() { $entity = \Yii::$app->getRequest()->getQueryParam('entity', null); $primaryKey = $this->entity->primaryKey(); return [['class' => ActionColumn::className(), 'buttons' => ['view' => function ($url, $model, $key) use($entity, $primaryKey) { return Html::a(Yii::t('admin', 'View'), ['manage/view', 'entity' => $entity, 'id' => $model->{$primaryKey}], ['class' => 'btn btn-primary']); }, 'update' => function ($url, $model, $key) use($entity, $primaryKey) { return Html::a(Yii::t('admin', 'Edit'), ['manage/update', 'entity' => $entity, 'id' => $model->{$primaryKey}], ['class' => 'btn btn-warning']); }, 'delete' => function ($url, $model, $key) use($entity, $primaryKey) { return Html::a(Yii::t('admin', 'Delete'), ['manage/delete', 'entity' => $entity, 'id' => $model->{$primaryKey}], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('admin', 'Are you sure you want to delete this item?'), 'method' => 'post']]); }]]]; }
/** * Load model * @param Entity $entity * @param string|integer $id * @return ActiveRecord mixed */ public function loadModel($entity, $id) { if ($this->_model) { return $this->_model; } /* @var ActiveRecord $modelClass */ $modelClass = $entity->getModelName(); /* @var ActiveQuery $query */ $query = call_user_func([$modelClass, 'find']); $query->where([$entity->primaryKey() => $id]); $condition = $entity->getModelConditions(); if (is_callable($condition)) { $query = call_user_func($condition, $query); } elseif (is_array($condition)) { $query = $query->andWhere($condition); } $this->_model = $query->one(); return $this->_model; }