Esempio n. 1
0
 /**
  * Handle Create or Update Workflow of a ZFDoctrine_Form_Model instance
  * 
  * @throws ZFDoctrine_DoctrineException
  * @param ZFDoctrine_Form_Model $form
  * @param string $action
  * @param string $controller
  * @param string $module
  * @param array $params
  * @return void
  */
 public function handleForm(ZFDoctrine_Form_Model $form, $action = null, $controller = null, $module = null, array $params = array())
 {
     $actionController = $this->getActionController();
     $request = $actionController->getRequest();
     if (!$action) {
         $action = $this->getActionController();
     }
     $id = null;
     $actionParams = array();
     if ($this->getRecordIdParam()) {
         $id = $request->getParam($this->getRecordIdParam());
         if ($id) {
             $actionParams = array($this->getRecordIdParam() => $id);
             $table = Doctrine_Core::getTable($form->getModelName());
             $record = $table->find($id);
             if (!$record) {
                 throw new ZFDoctrine_DoctrineException("Cannot find record with given id.");
             }
             $actionController->view->assign('recordId', $id);
             $actionController->view->assign('record', $record);
             $form->setRecord($record);
         }
     }
     $urlHelper = $actionController->getHelper('url');
     $form->setMethod('post');
     $form->setAction($urlHelper->simple($request->getActionName(), $request->getControllerName(), $request->getModuleName(), $actionParams));
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $form->save();
         $redirector = $actionController->getHelper('redirector');
         return $redirector->gotoSimple($action, $controller, $module, $params);
     }
     $actionController->view->assign('form', $form);
 }
Esempio n. 2
0
 public function testOneRelationSaving()
 {
     $this->_initAdapter('Comment');
     $article = array('id' => 1, 'name' => 'Test');
     $this->_adapter->expects($this->once())->method('getAllRecords')->with($this->equalTo('Article'))->will($this->returnValue(array($article)));
     $form = new ZFDoctrine_Form_Model(array('model' => 'Comment', 'adapter' => $this->_adapter));
     $this->assertType('Zend_Form_Element', $form->getElement('article_id'));
     $form->getElement('article_id')->setValue(1);
     $form->getElement('sender')->setValue('Sender');
     $this->_adapter->expects($this->any())->method('setRecordValues');
     $form->save();
 }