예제 #1
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);
 }