Example #1
0
 /**
  * Редактирует свойства страницы
  *
  * @param int $pageId id редактируемой страницы
  */
 public function actionEdit($pageId)
 {
     $page = Yii::app()->page->model;
     $form_array = Page::form();
     $form_array['id'] = sprintf('%x', crc32(serialize(array_keys($page->attributes))));
     $form_array['buttons'] = array('refresh' => array('type' => 'submit', 'label' => Yii::t('cms', 'Save'), 'title' => Yii::t('cms', 'Save and reload the page')));
     $form_array['activeForm'] = Form::ajaxify($form_array['id']);
     if ($page->id != 1) {
         $form_array['buttons']['deletepage'] = array('type' => 'submit', 'label' => Yii::t('cms', 'Delete'), 'title' => Yii::t('cms', 'Delete page'));
     }
     $form = new Form($form_array);
     $form->model = $page;
     $this->performAjaxValidation($page);
     if ($form->submitted('save') || $form->submitted('refresh')) {
         $page = $form->model;
         if ($form->validate()) {
             //$page->path = '';
             if ($page->save(false)) {
                 Yii::app()->user->setFlash('save', Yii::t('cms', 'Properties has been saved successfully'));
             } else {
                 Yii::app()->user->setFlash('save-error-permanent', Yii::t('cms', 'There is some error on page saving'));
             }
         }
     } elseif ($form->submitted('delete')) {
         $page = $form->model;
         if ($page->id != 1) {
             $parentId = $page->parent_id ? $page->parent_id : 1;
             $params = array('pageId' => $parentId);
             if ($page->parent_id) {
                 $params['url'] = $page->parent->url;
                 $params['alias'] = $page->parent->url;
             }
             echo CJavaScript::jsonEncode(array('url' => $this->createAbsoluteUrl('view/index', $params)));
             $page->delete();
             Yii::app()->user->setFlash('delete', Yii::t('cms', 'Page deleted.'));
             Yii::app()->end();
         }
     }
     $form = new Form($form_array);
     $form->model = $page;
     $caption = array('icon' => 'edit', 'label' => Yii::t('cms', 'Page properties'));
     $this->render('/form', array('form' => $form, 'caption' => $caption));
 }