/** * Generate form and display * * @return \Zend\View\Model\ViewModel|array */ public function editAction() { $coreConfig = $this->getServiceLocator()->get('CoreConfig'); $values = $coreConfig->getValues(); $this->form->setAttribute('action', $this->url()->fromRoute($this->getRouteMatch()->getMatchedRouteName())); $this->form->setValues($values); if ($this->getRequest()->isPost()) { $this->form->setData($this->getRequest()->getPost()->toArray()); if (!$this->form->isValid()) { $this->flashMessenger()->addErrorMessage('Can not save configuration'); $this->useFlashMessenger(); } else { $inputs = $this->form->getInputFilter()->getValidInput(); foreach ($inputs as $input) { if (method_exists($input, 'getName')) { $coreConfig->setValue($input->getName(), $input->getValue()); } } $this->flashMessenger()->addSuccessMessage('Configuration saved'); return $this->redirect()->toRoute($this->getRouteMatch()->getMatchedRouteName()); } } return array('form' => $this->form); }
/** * Test * * @return void */ public function testSetValues() { $this->object->initServer(Registry::get('Application')->getConfig()); $this->assertNull($this->object->setValues(array(array('identifier' => 'mail_from_name', 'value' => 'Pierre Rambaud')))); }