Exemple #1
5
 public function actionIndex()
 {
     $lang = new Lang();
     $lang->scenario = 'restcreate';
     $lang->attributes = ['name' => 'Deutsch', 'short_code' => 'de', 'is_default' => 0];
     $lang->save(false);
     foreach ($this->pages as $d) {
         $model = new Nav();
         $navItemId = $model->createPage($d['parent'], 1, 1, $d['title'], $d['alias'], 1, 'Description of ' . $d['title']);
         if ($navItemId) {
             $item = NavItem::findOne(['alias' => $d['alias']]);
             if ($item) {
                 $item->nav->updateAttributes(['is_offline' => 0, 'is_hidden' => 0]);
             }
         }
     }
     foreach ($this->redirects as $redir) {
         $model = new Nav();
         $redirItemId = $model->createRedirect($redir['parent'], 1, 1, $redir['title'], $redir['alias'], $redir['type'], $redir['typeValue'], 'Description of ' . $redir['title']);
         if ($redirItemId) {
             $item = NavItem::findOne(['alias' => $redir['alias']]);
             if ($item) {
                 $item->nav->updateAttributes(['is_offline' => 0, 'is_hidden' => 0]);
             }
         }
     }
 }
 public function actionCreateRedirect()
 {
     Yii::$app->menu->flushCache();
     $model = new Nav();
     $parentNavId = $this->postArg('parent_nav_id');
     $navContainerId = $this->postArg('nav_container_id');
     if (!empty($parentNavId)) {
         $navContainerId = Nav::findOne($parentNavId)->nav_container_id;
     }
     $create = $model->createRedirect($parentNavId, $navContainerId, $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $this->postArg('redirect_type'), $this->postArg('redirect_type_value'), $this->postArg('description'));
     if ($create !== true) {
         Yii::$app->response->statusCode = 422;
     }
     return $create;
 }