protected function findModel($id) { if (($model = Menu::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Menu::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'application_id' => $this->application_id, 'category_id' => $this->category_id, 'item_id' => $this->item_id, 'parent_id' => $this->parent_id, 'sort' => $this->sort, 'type' => $this->type]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'menu', $this->menu]); return $dataProvider; }
public function init() { if ($this->name !== null) { $cache_key = 'menu-' . $this->name; $items = Yii::$app->cache->get($cache_key); if ($items === false) { $items = $this->items; $menus = MenuModel::find()->where(['menu' => $this->name])->andWhere('parent_id IS NULL')->orderBy('sort')->all(); foreach ($menus as $name) { $items[] = $this->processItem($name); } $dependency = new \yii\caching\DbDependency(['sql' => 'SELECT MAX(updated_at) FROM ' . MenuModel::tableName()]); Yii::$app->cache->set($cache_key, $items, 86400, $dependency); } $this->items = $items; } parent::init(); }
public function getMenuList() { return M::find()->select(['menu'])->distinct()->indexBy('menu')->column(); }
public function getRelated() { return $this->hasMany(Menu::className(), ['parent_id' => 'id'])->orderBy('sort ASC'); }