Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MenuItem::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, 'parent_id' => $this->parent_id, 'level' => $this->level, 'position' => $this->position, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'uri', $this->uri]);
     return $dataProvider;
 }
Пример #2
0
?>

    <?php 
$this->beginBlock('basic');
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'uri')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'parent_id')->widget('common\\widgets\\McDropdown', array('data' => \mickey\menuItem\models\MenuItem::find()->where(['parent_id' => null])->with('children')->all(), 'options' => array('allowParentSelect' => true, 'select' => "js:function(id){\n                \$('#tab2').html('Сначала нужно сохранить пункт меню');\n            }"), 'options' => ['class' => 'span5']));
?>

    <?php 
$this->endBlock();
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('MenuItem', 'Create') : Yii::t('MenuItem', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>

        <?php 
if (!$model->isNewRecord) {
    echo Html::a(Yii::t('MenuItem', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('MenuItem', 'Are you sure you want to delete this item?'), 'method' => 'post']]);
    echo Html::a(Yii::t('MenuItem', 'Create'), ['create', 'root_id' => $model->parent_id], ['class' => 'btn btn-success']);
Пример #3
0
 public function actionSaveOrder()
 {
     if (isset($_POST['MenuItem_id'])) {
         $menuItems = MenuItem::find(['id' => $_POST['MenuItem_id']])->all();
         foreach ($menuItems as $menuItem) {
             $menuItem->position = array_search($menuItem->id, $_POST['MenuItem_id']);
             $menuItem->save();
         }
     } else {
         throw new \yii\web\HttpException(404, 'Invalid request. Please do not repeat this request again.');
     }
 }
Пример #4
0
 public function getNeighbors()
 {
     if ($this->_neighbors == null) {
         if ($this->isRooted) {
             $this->_neighbors = MenuItem::find()->root()->all();
         } else {
             $this->_neighbors = MenuItem::find()->where(['parent_id' => $this->parent_id])->all();
         }
     }
     return $this->_neighbors;
 }