Ejemplo n.º 1
0
 /**
  * Add action for article controller
  * @throws Exception
  */
 public function addAction()
 {
     // action body
     try {
         $translate = Zend_Registry::get('Zend_Translate');
         $frmArticle = new Content_Form_Article();
         $frmArticle->setAction($this->_request->getBaseUrl() . "/content/article/add");
         $this->view->frmArticle = $frmArticle;
         $mdlCategory = new Content_Model_Category();
         $categories = $mdlCategory->getSimpleList();
         $cbParent = $frmArticle->getElement('category_id');
         if (!$categories) {
             throw new Exception($translate->translate("CONTENT_CATEGORIES_EMPTY"));
         }
         foreach ($categories as $category) {
             $cbParent->addMultiOption($category->id, $category->title);
         }
         if ($this->getRequest()->isPost()) {
             if ($frmArticle->isValid($this->getRequest()->getParams())) {
                 $mdlArticle = new Content_Model_Article();
                 $article = $mdlArticle->createRow($frmArticle->getValues());
                 $article->introcontent = htmlentities($frmArticle->getElement('introcontent')->getValue());
                 $article->content = htmlentities($frmArticle->getElement('content')->getValue());
                 $mdlArticle->save($article);
                 $this->_helper->flashMessenger->addMessage(array('type' => 'info', 'header' => '', 'message' => $translate->translate("LBL_ITEM_CREATED_SUCCESSFULLY")));
                 $this->_helper->redirector("listregistered", "article", "content");
             }
         } else {
             #$fields = array();
             #foreach ( $frmArticle->getElements() as $element ) $fields[] = $element->getName();
             #$frmArticle->addDisplayGroup( $fields, 'form', array( 'legend' => $translate->translate("CONTENT_ADD_ARTICLE"), ) );
         }
     } catch (Exception $e) {
         $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $e->getMessage()));
         $this->_helper->redirector("listregistered", "article", "content");
     }
     return;
 }