/** * Creates a blog post * * @parmam void * @return mixed {Zend\Http\PhpEnvironment\Response, ViewModel} * @throws AccessProhibitedException **/ public function createAction() { $this->_checkAcl('create'); $userService = new UserService($this->_em); $auth = $userService->getAuthService(); $user = $userService->findById($auth->getIdentity()->getId()); $post = new Post(); $post->setDateAdded(new DateTime()); $post->setUser($user); $form = new PostForm(); $form->bind($post); $categoryService = new CategoryService($this->_em); $form->setCategoryList($categoryService->getAll()); $service = new PostService($this->_em); $service->setForm($form); $request = $this->getRequest(); if ($request->isPost()) { if ($service->save($request->getPost())) { $params = array('controller' => 'admin', 'action' => 'index'); return $this->redirect()->toRoute('blog/default', $params); } } return new ViewModel(array('form' => $form, 'messages' => $this->_postService->getMessages(PostService::MSG_NOTICE), 'errors' => $this->_postService->getMessages(PostService::MSG_ERROR))); }