コード例 #1
0
 /**
  * @return ViewModel
  */
 public function newAction()
 {
     $viewModel = new ViewModel();
     $order = new Order();
     if ($this->getRequest()->isPost()) {
         $this->orderInputFilter->setData($this->params()->fromPost());
         if ($this->orderInputFilter->isValid()) {
             $order = $this->hydrator->hydrate($this->orderInputFilter->getValues(), $order);
             $this->orders->begin()->persist($order)->commit();
             $this->flashMessenger()->addSuccessMessage('Order Created');
             $this->redirect()->toUrl('/orders/view/' . $order->getId());
         } else {
             $this->hydrator->hydrate($this->params()->fromPost(), $order);
             $viewModel->setVariable('errors', $this->orderInputFilter->getMessages());
         }
     }
     $viewModel->setVariable('customers', $this->customerRepository->getAll());
     $viewModel->setVariable('order', $order);
     return $viewModel;
 }
コード例 #2
0
 /**
  * @param Request $request
  * @return \Illuminate\View\View|RedirectResponse
  */
 public function newAction(Request $request)
 {
     $viewModel = [];
     $order = new Order();
     if ($request->getMethod() == 'POST') {
         $this->inputFilter->setData($request->request->all());
         if ($this->inputFilter->isValid()) {
             $order = $this->hydrator->hydrate($this->inputFilter->getValues(), $order);
             $this->orderRepository->begin()->persist($order)->commit();
             Session::flash('success', 'Order Saved');
             return new RedirectResponse('/orders/view/' . $order->getId());
         } else {
             $this->hydrator->hydrate($request->request->all(), $order);
             $viewModel['error'] = $this->inputFilter->getMessages();
         }
     }
     $viewModel['customers'] = $this->customerRepository->getAll();
     $viewModel['order'] = $order;
     return view('orders/new', $viewModel);
 }