GcConfig\Form\Config::setValues PHP Method

setValues() public method

Set config values from database result
public setValues ( array $data ) : void
$data array The data as array will by passed into form field
return void
    public function setValues(array $data)
    {
        foreach ($data as $config) {
            foreach ($this->getFieldsets() as $fieldset) {
                if ($fieldset->has($config['identifier'])) {
                    $fieldset->get($config['identifier'])->setValue($config['value']);
                    break;
                }
            }
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * 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);
 }
All Usage Examples Of GcConfig\Form\Config::setValues