Exemplo n.º 1
0
 /**
  * Initiliaze from array
  *
  * @param array $array Data
  *
  * @return Model
  */
 public static function fromArray(array $array)
 {
     $scriptTable = new Model();
     $scriptTable->setData($array);
     $scriptTable->setOrigData();
     if (empty($array['content'])) {
         $scriptTable->setContent($scriptTable->getContent());
     }
     return $scriptTable;
 }
Exemplo n.º 2
0
 /**
  * Create script
  *
  * @return \Zend\Script\Model\ScriptModel
  */
 public function createAction()
 {
     $scriptForm = new ScriptForm();
     $scriptForm->setAttribute('action', $this->url()->fromRoute('development/script/create'));
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost()->toArray();
         $scriptForm->setData($data);
         if (!$scriptForm->isValid()) {
             $this->flashMessenger()->addErrorMessage('Can not save script');
             $this->useFlashMessenger();
         } else {
             $scriptModel = new Script\Model();
             $scriptModel->setName($scriptForm->getValue('name'));
             $scriptModel->setIdentifier($scriptForm->getValue('identifier'));
             $scriptModel->setDescription($scriptForm->getValue('description'));
             $scriptModel->setContent($scriptForm->getValue('content'));
             $scriptModel->save();
             $this->flashMessenger()->addSuccessMessage('This script has been created');
             return $this->redirect()->toRoute('development/script/edit', array('id' => $scriptModel->getId()));
         }
     }
     return array('form' => $scriptForm);
 }