예제 #1
0
 public function component_edit()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.cms.component', true, '/cms/component');
     // check
     $id = Converter::int('id');
     $component = \Rebond\Cms\Component\Data::loadById($id, true);
     $form = new \Rebond\Cms\Component\Form($component);
     // action
     if (isset($_POST['save'])) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.cms.component.edit', true, '/cms/component?id=' . $id);
         if ($form->setFromPost()->validate()->isValid()) {
             $component->save();
             Session::adminSuccess('saved', '/cms/component');
         } else {
             Session::set('adminError', $form->getValidation()->getMessage());
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Template(Template::MODULE, ['cms', 'component']);
     $tplMain->set('item', $form);
     // layout
     if (Auth::isAdminAuthorized($this->signedUser, 'admin.cms.component.edit', false)) {
         $this->tplLayout->set('column1', $tplMain->render('editor'));
     } else {
         $this->tplLayout->set('column1', $tplMain->render('view'));
     }
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     $this->tplMaster->set('jsLauncher', 'cmsComponentEdit');
     return $this->tplMaster->render('tpl-default');
 }
예제 #2
0
 public function getComponent($createIfNotExist = false)
 {
     if (!isset($this->component)) {
         $this->component = \Rebond\Cms\Component\Data::loadById($this->componentId, $createIfNotExist);
     }
     return $this->component;
 }