Ejemplo n.º 1
0
 public function saveAction()
 {
     $form = $this->getForm();
     $request = $this->getRequest();
     $id = $this->params('id');
     if ($request->isPost()) {
         $data = $request->getPost();
         $form->setData($data);
         $race = new Race();
         $form->setInputFilter($race->getInputFilter());
         if ($form->isValid()) {
             try {
                 $race->exchangeArray($form->getData());
                 $this->serviceLocator->get('races')->save($race->getArrayCopy());
             } catch (\Exception $e) {
             }
             return $this->redirect()->toRoute('application/default', ['controller' => 'race']);
         }
     } elseif ($id) {
         $data = $this->serviceLocator->get('races')->findById($id);
         $form->setData($data);
     }
     $viewModel = new ViewModel();
     $viewModel->setVariables(['form' => $form]);
     $viewModel->setTemplate('application/race/form.phtml');
     return $viewModel;
 }
Ejemplo n.º 2
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage \Application\Model\Race::RACE_ALREADY_SIMULATED
  */
 public function testSimulateAlreadyDone()
 {
     $race = new Race();
     $race->addKart(new Kart());
     $race->addKart(new Kart());
     $race->simulate();
     $race->simulate();
 }