コード例 #1
0
 /**
  * Prepares the data provider that should return the requested collection of the models.
  * @param string $id the primary key of the model.
  * @return ActiveDataProvider
  */
 protected function prepareDataProvider($id)
 {
     if ($this->prepareDataProvider !== null) {
         return call_user_func($this->prepareDataProvider, $this);
     }
     return new ActiveDataProvider(['query' => $this->level && $this->level !== 1 ? MenuItem::find()->where(['menu_id' => $id])->andWhere(['<', 'depth', $this->level]) : MenuItem::find()->where(['menu_id' => $id])->roots()]);
 }
コード例 #2
0
ファイル: Menu.php プロジェクト: manyoubaby123/imshop
 /**
  * @inheritdoc
  */
 public function run()
 {
     $items = MenuItem::find()->where(['menu_id' => 1, 'status' => MenuItem::STATUS_ACTIVE])->with(['icon', 'activeIcon', 'video'])->all();
     if ($items) {
         $items = TreeHelper::buildNodesTree($items);
     }
     return $this->render('menu/menu', ['widget' => $this, 'items' => $items]);
 }
コード例 #3
0
 /**
  * Prepares the data provider that should return the requested collection of the models.
  * @param string $id the primary key of the model.
  * @return ActiveDataProvider
  */
 protected function prepareDataProvider($id)
 {
     if ($this->prepareDataProvider !== null) {
         return call_user_func($this->prepareDataProvider, $this);
     }
     $query = MenuItem::find()->where(['menu_id' => $id]);
     $data = \Yii::$app->getRequest()->getBodyParams();
     $string = isset($data['string']) ? $data['string'] : '';
     if ($this->searchableAttributes) {
         $condition = ['or'];
         foreach ($this->searchableAttributes as $attribute) {
             $condition[] = ['like', $attribute, $string];
         }
         $query->andWhere($condition);
         /** @var $models MenuItem[] */
         $models = $query->all();
         foreach ($models as $model) {
             $query->union($model->parents());
         }
     }
     return new ActiveDataProvider(['query' => $query]);
 }
コード例 #4
0
ファイル: Menu.php プロジェクト: xyxdasnjss/imshop
 /**
  * @inheritdoc
  */
 public function run()
 {
     $items = MenuItem::find()->where(['menu_id' => 1, 'status' => MenuItem::STATUS_ACTIVE])->all();
     $items = TreeHelper::buildNodesTree($items);
     return $this->render('menu/menu', ['widget' => $this, 'items' => $items, 'level' => 1]);
 }