Пример #1
0
 public function editAction()
 {
     $auth = $this->getServiceLocator()->get('zfcuser_auth_service');
     $user = $auth->getIdentity();
     $template = $this->templateService->getTemplateById($this->params('id'));
     $form = $this->getServiceLocator()->get('Application\\Form\\Template')->init();
     $form = $form->setFormValues($template);
     $view = new ViewModel();
     if (!$template) {
         return $this->redirect()->toRoute('application/default', array('controller' => 'template', 'action' => 'index'));
     }
     if ($this->request->isPost()) {
         $form->setData($this->request->getPost());
         if ($form->isValid()) {
             $template = $this->templateService->saveWithParams($template, $user, $form->getData());
             $translator = $this->serviceLocator->get('MvcTranslator');
             $this->flashMessenger()->addMessage($translator->translate('Controller.Template.Edit.TemplateSaved'));
             $this->redirect()->toRoute('application/default', array('controller' => 'template', 'action' => 'edit', 'id' => $template->getId(), 'code' => $template->getCode()));
         }
     }
     $view->template = $template;
     $view->messages = $this->flashMessenger()->getMessages();
     $view->form = $form;
     $view->code = $this->params('code');
     return $view;
 }