public function detailAction()
 {
     $newsUrl = $this->getRequest()->getParam('url', null);
     try {
         $news = $this->newsRepository->fetchEntityByUrl($newsUrl);
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage(), 404);
     }
     $this->view->headTitle($news->headline);
     $this->view->headMeta()->setName('description', $this->_helper->truncate($news->content, 255));
     $configForm = $this->getInvokeArg('bootstrap')->getResource('configForm');
     $commentForm = new \Zend_Form($configForm->comment);
     if ($this->getRequest()->isPost()) {
         if ($commentForm->isValid($_POST)) {
             try {
                 $values = $commentForm->getValues();
                 unset($values['csrf']);
                 unset($values['firstname']);
                 # SpamDetection
                 $values['news'] = $news;
                 $this->commentRepository->saveEntity($values);
                 $commentForm->reset();
                 #$this->_helper->systemMessages('notice', 'Kommentar erfolgreich gespeichert');
             } catch (\Exception $e) {
                 $log = $this->getInvokeArg('bootstrap')->log;
                 $log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
                 #$this->_helper->systemMessages('error', 'Kommentar konnte nicht gespeichert werden');
             }
         }
     }
     $commentForm->setAction('/news/' . $newsUrl);
     $this->view->form = $commentForm;
     $this->view->news = $news;
 }
Exemple #2
0
 /**
  * @group ZF-3227
  */
 public function testFormsShouldAllowResetting()
 {
     $form = new Zend_Form();
     $foo = new Zend_Form_SubForm(array('name' => 'foo', 'elements' => array('one' => 'text', 'two' => 'text')));
     $form->addElement('text', 'bar')->addElement('text', 'baz')->addElement('text', 'bat')->addDisplayGroup(array('bar', 'bat'), 'barbat')->addSubForm($foo, 'foo');
     $values = array('bar' => 'Bar Value', 'baz' => 'Baz Value', 'bat' => 'Bat Value', 'foo' => array('one' => 'One Value', 'two' => 'Two Value'));
     $form->populate($values);
     $test = $form->getValues();
     $this->assertEquals($values, $test);
     $form->reset();
     $test = $form->getValues();
     $this->assertNotEquals($values, $test);
     $this->assertEquals(0, array_sum($test));
 }
 /**
  * Reset values of form
  *
  * @return Zend_Form
  */
 public function reset()
 {
     $this->getSessionNamespace()->unsetAll();
     return parent::reset();
 }