Example #1
0
 /**
  * The function shows edit form and saves data on submit.
  * 
  * @access private
  * @param object $Page The Content Page object.
  * @return string The HTML code.
  */
 protected function initForm(Content_Page $Page)
 {
     if (isset($_POST['submit'])) {
         $Page->setPost($_POST);
         $fields = Error::test($Page);
         if (count($fields)) {
             $this->getView()->set('Error', 'Неверно заполены поля: ' . implode(', ', $fields));
         } else {
             if ($Page->save()) {
                 if ($Page->Module && $Page->Link) {
                     Router::attachPage($Page);
                 } else {
                     Router::detachPage($Page);
                 }
                 return $this->halt('', true);
             } else {
                 $this->getView()->set('Error', 'Ошибка записи данных: ' . $Page->getError() . "\n" . Database::getInstance()->getLastQuery());
             }
         }
     }
     $Document = new Document();
     $this->getView()->set('Documents', $Document->findList(array(), 'Position asc'));
     $this->getView()->set('Page', $Page);
     return $this->getView()->render();
 }