/** * @return Response */ public function actionOrdering() { $data = Yii::$app->request->getBodyParam('data', []); foreach ($data as $id => $order) { if ($target = MenuItem::findOne($id)) { $target->updateAttributes(['ordering' => intval($order)]); } } MenuItem::find()->roots()->one()->reorderNode('ordering'); DbState::updateState(MenuItem::tableName()); return $this->redirect(ArrayHelper::getValue(Yii::$app->request, 'referrer', ['index'])); }
/** * @return array */ public function getItems() { if (!isset($this->_items)) { if ($cache = $this->ensureCache()) { $cacheKey = [__CLASS__, $this->type, $this->activateItems, $this->activateParents, $this->language]; if (($this->_items = $cache->get($cacheKey)) === false) { $this->_items = $this->items(); $cache->set($cacheKey, $this->_items, $this->cacheDuration, $this->cacheDependency ? $this->cacheDependency : DbState::dependency(MenuItem::tableName())); } } else { $this->_items = $this->items(); } } return $this->_items; }