當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Post::isAuthor方法代碼示例

本文整理匯總了PHP中AppBundle\Entity\Post::isAuthor方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::isAuthor方法的具體用法?PHP Post::isAuthor怎麽用?PHP Post::isAuthor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AppBundle\Entity\Post的用法示例。


在下文中一共展示了Post::isAuthor方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: isEditGranted

 /**
  * @param Post $post
  * @param User $user
  *
  * @return bool
  */
 private function isEditGranted(Post $post, User $user)
 {
     switch ($post->getState()) {
         case Post::STATUS_DRAFT:
             return $post->isAuthor($user);
         case Post::STATUS_REVIEW:
             return $user->isAdmin();
     }
     return false;
 }
開發者ID:panayotovyura,項目名稱:levi9voter,代碼行數:16,代碼來源:PostVoter.php

示例2: editAction

 /**
  * Makale düzenleme
  *
  * @Route("/{id}/edit", requirements={"id" = "\d+"}, name="admin_post_edit")
  * @Method({"GET", "POST"})
  * @param Post $post
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function editAction(Post $post, Request $request)
 {
     if (null === $this->getUser() || !$post->isAuthor($this->getUser())) {
         throw $this->createAccessDeniedException('Posts can only be edited by their authors.');
     }
     $entityManager = $this->getDoctrine()->getManager();
     $editForm = $this->createForm('AppBundle\\Form\\PostType', $post);
     $deleteForm = $this->createDeleteForm($post);
     $editForm->handleRequest($request);
     if ($editForm->isSubmitted() && $editForm->isValid()) {
         $post->setSlug($this->get('slugger')->slugify($post->getTitle()));
         $entityManager->flush();
         $this->addFlash('success', 'Makale başarıyla güncellendi');
         return $this->redirectToRoute('admin_post_edit', array('id' => $post->getId()));
     }
     return $this->render('admin/blog/edit.html.twig', array('post' => $post, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()));
 }
開發者ID:alisan-alacam,項目名稱:blog,代碼行數:26,代碼來源:BlogController.php

示例3: editAction

 /**
  * Displays a form to edit an existing Post entity.
  *
  * @Route("/{id}/edit", requirements={"id" = "\d+"}, name="admin_post_edit")
  * @Method({"GET", "POST"})
  * @Security("has_role('ROLE_USER')")
  */
 public function editAction(Post $post, Request $request)
 {
     if (null === $this->getUser() || !$post->isAuthor($this->getUser())) {
         throw $this->createAccessDeniedException('Posts can only be edited by their authors.');
     }
     if ($post->getState() !== Post::STATUS_DRAFT) {
         return $this->redirectToRoute('admin_post_index');
     }
     $em = $this->getDoctrine()->getManager();
     $editForm = $this->createForm(new PostType(), $post);
     $deleteForm = $this->createDeleteForm($post);
     $editForm->handleRequest($request);
     if ($editForm->isSubmitted() && $editForm->isValid()) {
         $post->setSlug($this->get('slugger')->slugify($post->getTitle()));
         if ($request->request->has('publish')) {
             $post->setState(Post::STATUS_VOTING);
         }
         $em->flush();
         return $this->redirectToRoute('admin_post_edit', array('id' => $post->getId()));
     }
     return $this->render('admin/blog/edit.html.twig', array('post' => $post, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()));
 }
開發者ID:panayotovyura,項目名稱:levi9voter,代碼行數:29,代碼來源:BlogController.php

示例4: editAction

 /**
  * Displays a form to edit an existing Post entity.
  *
  * @Route("/{id}/edit", requirements={"id" = "\d+"}, name="user_post_edit")
  * @Method({"GET", "POST"})
  */
 public function editAction(Post $post, Request $request)
 {
     if (null === $this->getUser() || !$post->isAuthor($this->getUser())) {
         throw $this->createAccessDeniedException('Posts can only be edited by their authors.');
     }
     $entityManager = $this->getDoctrine()->getManager();
     $editForm = $this->createForm(new PostType(), $post);
     $deleteForm = $this->createDeleteForm($post);
     $editForm->handleRequest($request);
     if ($editForm->isSubmitted() && $editForm->isValid()) {
         $post->setSlug($this->get('slugger')->slugify($post->getTitle()));
         $entityManager->flush();
         // ??
         $this->addFlash('success', 'post.updated_successfully');
         // -- repair
         return $this->redirectToRoute('user_post_edit', array('id' => $post->getId()));
     }
     // -- repair
     return $this->render('user/blog/edit.html.twig', array('post' => $post, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()));
 }
開發者ID:quangtuanle,項目名稱:alano_project,代碼行數:26,代碼來源:BlogController.php


注:本文中的AppBundle\Entity\Post::isAuthor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。