menu_id = $menu_id; $menu->parent_id = $parent_id; $menu->name = $name; $menu->title_attr = $title_attr; $menu->target = $target; $menu->css = $css; $menu->style = $style; $menu->module = $module; $menu->url = $url; $menu->url_params = $url_params; return $menu; } public function edit($menu_id, $parent_id, $name, $title_attr, $target, $css, $style, $module, $url, $url_params): void { $this->menu_id = $menu_id; $this->parent_id = $parent_id; $this->name = $name; $this->title_attr = $title_attr; $this->target = $target; $this->css = $css; $this->style = $style; $this->module = $module; $this->url = $url; $this->url_params = $url_params; } public static function tableName(): string { return '{{%menu_items}}'; } /*public function behaviors() { return [ [ 'class' => SortableBehavior::class, 'query' => ['menu_id'], ], ]; }*/ public function beforeSave( $insert ) { if (parent::beforeSave($insert)) { if (!isset($this->sort)) { $count = MenuItem::find() ->andWhere( [ 'menu_id' => $this->menu_id ] ) ->andWhere( [ 'parent_id' => $this->parent_id ] ) ->count(); $this->sort = $count; } return true; } return false; } public function getChildren() { return $this->hasMany(MenuItem::class, ['parent_id' => 'id'])->orderBy(['sort' => SORT_ASC]); } public function getParent() { return $this->hasOne(MenuItem::class, ['id' => 'parent_id']); } }