/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = TakonomyCategory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\grid\GridView; use source\LuLu; use source\core\lib\Common; use source\models\Takonomy; use source\models\TakonomyCategory; /* @var $this yii\web\View */ /* @var $searchModel app\models\search\TakonomySearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title='分类项'; $category=LuLu::getGetValue('category'); $categoryModel = TakonomyCategory::findOne(['id'=>$category]); $this->addBreadcrumbs([ ['分类管理',['/takonomy']], $categoryModel['name'], ]); ?> <div class="mod"> <div class="mod-head"> <h3> <span class="pull-left"><?= $categoryModel['name']?></span> <span class="pull-right"><?= Html::a('新建', ['create','category'=>$category], ['class' => 'btn btn-xs btn-primary mod-site-save']) ?></span> <span class="pull-right"><?= Html::a('返回', ['/takonomy/takonomy-category/index'], ['class' => 'btn btn-xs btn-primary mod-site-save']) ?></span>
/** * Finds the TakonomyCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return TakonomyCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TakonomyCategory::findOne(['id' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function getTakonomyCategories() { $categories = TakonomyCategory::findAll([], 'name asc'); return $categories; }