public function actionSort() 
    {
        $this->layout = static::FORM_LAYOUT;
        $modelName = $this->getCompatibilityId();
        if(isset($_POST[$modelName]) && count($_POST[$modelName])) {
            //If we are changing the main categories then use a different algorithm
            if($_GET['Menu_id']==-1) {
                foreach($_POST[$modelName] as $key => $id) {
                    $record = $this->findModel($id);
                    $record->sort_order = $key+1;
                    $record->save();
                }
            } else {
                $parent = $this->findModel($_GET['Menu_id']);
                foreach($_POST[$modelName] as $key => $id) {
                    $record = $this->findModel($id);
                    $record->appendTo($parent);
                }
            }
            return $this->redirect(['index']);
        } else {
            $this->getSearchCriteria();
            $searchCriteria = ['MenuSearch' => ['Menu_id' => $this->searchModel->Menu_id]];
            $this->searchModel = new $this->MainModelSearch;
            $this->dataProvider = $this->searchModel->search($searchCriteria);

            $this->dataProvider->pagination = false;
            return $this->render('sort', [
                'searchModel' => $this->searchModel,
                'dataProvider' => $this->dataProvider,
            ]);         
        }
    }
public function actionSort() 
    {
        $this->layout = static::FORM_LAYOUT;
        $modelName = $this->getCompatibilityId();
        if(isset($_POST[$modelName]) && count($_POST[$modelName])) {
            //If we are changing the main categories then use a different algorithm
            if($_GET['Menu_id']==-1) {
                foreach($_POST[$modelName] as $key => $id) {
                    $record = $this->findModel($id);
                    $record->sort_order = $key+1;
                    $record->save();
                }
            } else {
                $parent = $this->findModel($_GET['Menu_id']);
                foreach($_POST[$modelName] as $key => $id) {
                    $record = $this->findModel($id);
                    $record->appendTo($parent);
                }
            }
            return $this->redirect(['index']);
        } else {
            $this->getSearchCriteria();
            $searchCriteria = ['MenuSearch' => ['Menu_id' => $this->searchModel->Menu_id]];
            $this->searchModel = new $this->MainModelSearch;
            $this->dataProvider = $this->searchModel->search($searchCriteria);

            $this->dataProvider->pagination = false;
            return $this->render('sort', [
                'searchModel' => $this->searchModel,
                'dataProvider' => $this->dataProvider,
            ]);         
        }
    }
public function actionSort ( ) { $ this -> layout = static :: FORM_LAYOUT ; $ modelName = $ this -> getCompatibilityId ( ) ; if ( isset ( $ _POST [ $ modelName ] ) && count ( $ _POST [ $ modelName ] ) ) { //If we are changing the main categories then use a different algorithm if ( $ _GET [ 'Menu_id' ] == - 1 ) { foreach ( $ _POST [ $ modelName ] as $ key => $ id ) { $ record = $ this -> findModel ( $ id ) ; $ record -> sort_order = $ key + 1 ; $ record -> save ( ) ; } } else { $ parent = $ this -> findModel ( $ _GET [ 'Menu_id' ] ) ; foreach ( $ _POST [ $ modelName ] as $ key => $ id ) { $ record = $ this -> findModel ( $ id ) ; $ record -> appendTo ( $ parent ) ; } } return $ this -> redirect ( [ 'index' ] ) ; } else { $ this -> getSearchCriteria ( ) ; $ searchCriteria = [ 'MenuSearch' => [ 'Menu_id' => $ this -> searchModel -> Menu_id ] ] ; $ this -> searchModel = new $ this -> MainModelSearch ; $ this -> dataProvider = $ this -> searchModel -> search ( $ searchCriteria ) ; $ this -> dataProvider -> pagination = false ; return $ this -> render ( 'sort' , [ 'searchModel' => $ this -> searchModel , 'dataProvider' => $ this -> dataProvider , ] ) ; } }
Allows sorting of the menus
Allows sorting of the menus