public function addAction() { $formJob = new JobForm($this->categoryTable); $request = $this->getRequest(); if ($request->isPost()) { $job = new Job(); $formJob->setInputFilter($job->getInputFilter()); $nonFiles = $this->getRequest()->getPost()->toArray(); $files = $this->getRequest()->getFiles()->toArray(); $data = array_merge_recursive($nonFiles, $files); $formJob->setData($data); if ($formJob->isValid()) { $size = new Size(array('max' => 716800)); $adapter = new \Zend\File\Transfer\Adapter\Http(); $adapter->setValidators(array($size), $files['logo']); if (!$adapter->isValid()) { $dataError = $adapter->getMessages(); $error = array(); foreach ($dataError as $key => $row) { $error[] = $row; } $formJob->setMessages(array('logo' => $error)); } else { $adapter->setDestination('./public/resources'); if ($adapter->receive($files['logo']['name'])) { $job->exchangeArray($formJob->getData()); $job->logo = $files['logo']['name']; $this->jobTable->saveJob($job); return $this->redirect()->toRoute('home'); } } } } return new ViewModel(array('form' => $formJob)); }
public function editAction() { $request = $this->getRequest(); $formJob = new JobForm($this->categoryTable); $formJob->get('submit')->setValue('Modifier'); $idJob = $this->params()->fromRoute('id', null); if ($request->isPost()) { $job = $this->getServiceLocator()->get('Jobeet/Model/Job'); $formJob->setData($request->getPost()); $job->id_job = $idJob; $formJob->setInputFilter($job->getInputFilter()); if ($formJob->isValid()) { $job->exchangeArray($formJob->getData()); $this->jobTable->saveJob($job); $this->flashMessenger()->addMessage(array('success' => "Job '{$job->id_job}' was updated successfully")); return $this->redirect()->toRoute('zfcadmin/job'); } else { Debug::dump($formJob); } } $job = $this->jobTable->getJob($idJob); $formJob->setData($job->getArrayCopy()); return new ViewModel(array('form' => $formJob)); }