示例#1
1
 public function saveAction()
 {
     $form = $this->getForm();
     $request = $this->getRequest();
     $id = $this->params('id');
     if ($request->isPost()) {
         $data = $request->getPost();
         $form->setData($data);
         $kart = new Kart();
         $form->setInputFilter($kart->getInputFilter());
         if ($form->isValid()) {
             try {
                 $kart->exchangeArray($form->getData());
                 $this->serviceLocator->get('karts')->save($kart->getArrayCopy());
             } catch (\Exception $e) {
             }
             return $this->redirect()->toRoute('application/default', ['controller' => 'kart']);
         }
     } elseif ($id) {
         $kartData = $this->serviceLocator->get('karts')->findById($id);
         $form->setData($kartData);
     }
     $viewModel = new ViewModel();
     $viewModel->setVariables(['form' => $form]);
     $viewModel->setTemplate('application/kart/form.phtml');
     return $viewModel;
 }
示例#2
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage \Application\Model\Kart::LAP_TIME_VALUE
  */
 public function testSetLapTimeOverValueFail()
 {
     $kart = new Kart();
     $lapTime = 300000;
     $kart->setLapTime($lapTime);
 }