예제 #1
0
 /**
  * Create
  *
  * POST
  */
 public function createAction()
 {
     if (!$this->_request->isPost()) {
         $this->_redirect($this->_helper->url('new'));
     }
     require_once APPLICATION_PATH . '/forms/NewPhotoForm.php';
     $form = new NewPhotoForm();
     $form->setAction($this->_helper->url->simple('create'));
     $this->view->form = $form;
     if (!$form->isValid($this->_request->getPost())) {
         $this->view->messages = $form->getMessages();
         return $this->render('new');
     }
     if (!$form->file->receive()) {
         $this->view->messages = array(array('failed' => 'Failed to upload the image'));
     }
     $adapter = $form->file->getTransferAdapter();
     $file = $adapter->getFileName('file');
     $model = $this->_getPhotoModel();
     $id = $model->add($form->getValues(), $file);
     // Should probably not be here, but it works for now...
     unlink($file);
     $this->_redirect($this->_helper->url('edit', null, null, array('id' => $id)));
 }