Esempio n. 1
0
 /**
  * Create or update new page
  * @param boolean $new
  */
 public function actionUpdate($new = false)
 {
     if ($new === true) {
         $model = new Page();
     } else {
         $model = Page::model()->cache($this->cacheTime)->language(Yii::app()->language->active)->findByPk($_GET['id']);
     }
     $this->breadcrumbs = array(Yii::t('PagesModule.default', 'MODULE_NAME') => $this->createUrl('index'), $model->isNewRecord ? $model->t('PAGE_TITLE', 0) : CHtml::encode($model->title));
     $this->pageName = $model->isNewRecord ? $model->t('PAGE_TITLE', 0) : $model->t('PAGE_TITLE', 1);
     if (!$model) {
         throw new CHttpException(404);
     }
     if (Yii::app()->request->isPostRequest) {
         $model->attributes = $_POST['Page'];
         if ($model->validate()) {
             $model->save();
             if ($model->in_menu == 1) {
                 $isset = MenuModel::model()->findByAttributes(array('url' => '/page/' . $model->seo_alias));
                 if (!isset($isset)) {
                     $menu = new MenuModel();
                     $menu->label = $model->title;
                     $menu->url = '/page/' . $model->seo_alias;
                     if ($menu->validate()) {
                         $menu->save(false, false);
                     }
                 }
             }
             $this->redirect(array('index'));
         }
     }
     $this->render('update', array('model' => $model));
 }
Esempio n. 2
0
 public function actionCreate()
 {
     $status = 1;
     $msg = '添加成功';
     if ($_POST) {
         $parentId = intval($_POST['parentId']);
         $name = $_POST['name'];
         if ($parentId > 0) {
             if (mb_strlen($name, 'utf8') > 7) {
                 $status = -1;
                 $msg = '二级菜单名称不能超过7个汉字';
             }
             //当前菜单的子菜单个数
             $count = MenuModel::model()->count('wechatId = :wechatId and parentId=:parentId', array(':wechatId' => $this->wechatInfo->id, ':parentId' => $parentId));
             if ($count >= 5) {
                 $status = -1;
                 $msg = '二级菜单不能超过5个';
             }
         } else {
             if (mb_strlen($name, 'utf8') > 4) {
                 $status = -1;
                 $msg = '一级菜单名称不能超过4个汉字';
             }
             //一级菜单个数
             $count = MenuModel::model()->count('wechatId = :wechatId and parentId=:parentId', array(':wechatId' => $this->wechatInfo->id, ':parentId' => 0));
             if ($count >= 3) {
                 $status = -1;
                 $msg = '一级菜单不能超过3个';
             }
         }
         if ($status == 1) {
             $modelAction = new MenuactionModel();
             $modelAction->action = $_POST['type'] == Globals::TYPE_URL ? $_POST['url'] : $_POST['action'];
             $model = new MenuModel();
             $model->name = $name;
             $model->wechatId = $this->wechatInfo->id;
             $model->type = $_POST['type'];
             $model->parentId = $_POST['parentId'] ? $_POST['parentId'] : 0;
             //responseId 响应ID
             if ($_POST['type'] == Globals::TYPE_KEYWORDS || $_POST['type'] == Globals::TYPE_GIFT) {
                 //如果是关键词则需要找到对应的responseId
                 $keyword = KeywordsModel::model()->find("wechatId=:wechatId and name like concat('%',:name,'%') order by id desc", array(':wechatId' => $this->wechatInfo->id, ':name' => $_POST['action']));
                 if (!empty($keyword->responseId)) {
                     $model->responseId = $keyword->responseId;
                 } else {
                     $msg = '不存在该关键词';
                 }
             }
             if ($model->validate() && $modelAction->validate()) {
                 $model->save();
                 $modelAction->menuId = $model->id;
                 $modelAction->save();
             } else {
                 $status = -1;
                 $error = $model->getErrors();
                 if ($error) {
                     foreach ($error as $e) {
                         $msg .= $e[0];
                     }
                 }
             }
         }
     }
     echo json_encode(array('status' => $status, 'msg' => $msg));
 }
Esempio n. 3
0
 /**
  * 菜单项 编辑后更新数据库
  */
 function update()
 {
     $menu = new MenuModel();
     if (($data = $menu->create()) !== false) {
         //如果传了主键ID过来了,这个是我隐形hidden传的
         if (!empty($data['id'])) {
             $menu->save($data);
             $this->assign('jumpUrl', __URL__ . '/index');
             $this->success('菜单更新成功');
         } else {
             $this->assign('jumpUrl', __URL__ . '/index');
             $this->error('请选择菜单项');
         }
     } else {
         $this->assign('jumpUrl', __URL__ . '/index');
         $this->error('数据出错' . $menu->getError());
     }
 }