コード例 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Nav();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Nav'])) {
         $model->attributes = $_POST['Nav'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', '操作成功!');
             $this->redirect(array('index'));
         }
     }
     $this->render('create', array('model' => $model));
 }
コード例 #2
0
 public function setNav()
 {
     $nav = new Nav();
     $nav->title = "首页";
     $nav->activeRule = 'return Yii::app()->controller->activeMenu=="site";';
     $nav->url = "/";
     $nav->save();
     $nav = new Nav();
     $nav->title = "课程";
     $nav->activeRule = 'return Yii::app()->controller->activeMenu=="course";';
     $nav->url = "/course";
     $nav->save();
     $nav = new Nav();
     $nav->title = "小组";
     $nav->activeRule = 'return Yii::app()->controller->activeMenu=="group";';
     $nav->url = "/group";
     $nav->save();
     $nav = new Nav();
     $nav->title = "资讯";
     $nav->activeRule = 'return Yii::app()->controller->activeMenu=="article";';
     $nav->url = "/cms/article";
     $nav->save();
     $nav = new Nav();
     $nav->title = "师资";
     $nav->activeRule = 'return Yii::app()->controller->activeMenu=="people";';
     $nav->url = "/cms/people";
     $nav->save();
 }
コード例 #3
0
 /**
  * Store all type of menu, parent, child internal or external link and button
  *
  * @return Response
  */
 public function store()
 {
     $rules = array();
     $navigation_title_datas = array();
     foreach (Input::except('_token') as $k => $v) {
         if (strpos($k, 'navigation_title_') !== false) {
             $rules[$k] = Config::get('validator.admin.navigation_title.title');
             $navigation_title_datas[mb_substr($k, strlen('navigation_title_'), strlen($k) - strpos($k, 'navigation_title_'))] = $v;
         }
     }
     $rules = array_merge($rules, Config::get('validator.admin.navigation'));
     //return var_dump($rules);
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->passes()) {
         //create i18n key
         $i18n_title = new I18n();
         $i18n_title->i18n_type_id = I18nType::where('name', '=', 'navigation')->first()->id;
         $i18n_title->save();
         foreach ($navigation_title_datas as $locale => $value) {
             if (!$i18n_title->translate($locale, $value)) {
                 return Redirect::to('admin/navigation')->with('error', Lang::get('admin.navigation_save_fail'));
             }
         }
         $navigation = new Nav();
         $navigation->i18n_title = $i18n_title->id;
         if (Input::has('parent_id')) {
             $navigation->parent_id = Input::get('parent_id');
         } else {
             $navigation->parent_id = 0;
         }
         //There case : external link, internal link and link container (button)
         if (Input::has('url_external')) {
             //create a link and put the id in the navigable_id :)
             $nav_link = new NavLink();
             $nav_link->url = Input::get('url_external');
             $nav_link->save();
             $navigation->navigable_id = $nav_link->id;
             $navigation->navigable_type = 'NavLink';
         }
         if (Input::has('model_resource_id')) {
             $result_explode = explode('|', Input::get('model_resource_id'));
             $navigation->navigable_id = $result_explode[1];
             $navigation->navigable_type = $result_explode[0];
         }
         if (!Input::has('url_external') && !Input::has('model_resource_id')) {
             $nav_link = new NavLink();
             $nav_link->url = '#';
             $nav_link->save();
             $navigation->navigable_id = $nav_link->id;
             $navigation->navigable_type = 'NavLink';
         }
         if (Input::has('order')) {
             $navigation->order = Input::get('order');
         } else {
             $navigation->order = Nav::max() + 1;
         }
         // Was the blog post created?
         if ($navigation->save()) {
             //track user
             parent::track('create', 'Navigation', $navigation->id);
             Cache::forget('DB_Nav');
             // Redirect to the new blog post menu
             return Redirect::to('admin/navigation')->with('success', 'Le menu à bien été ajouté !');
         }
         // Redirect to the blog post create menu
         return Redirect::to('admin/navigation/create')->with('error', 'Le menu n\'a pas pu être enregistrée...');
     }
     // Form validation failed
     return Redirect::to('admin/navigation/create')->withInput()->withErrors($validator);
 }