• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Entity\Post类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中AppBundle\Entity\Post的典型用法代码示例。如果您正苦于以下问题:PHP Post类的具体用法?PHP Post怎么用?PHP Post使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Post类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: createAction

 /**
  * @Route("/create", name="create_objects")
  *
  * @Rest\View()
  *
  * @return Response
  */
 public function createAction()
 {
     // We need an entity manager here
     $em = $this->getDoctrine()->getManager();
     // First, we try to create a post
     $post = new Post();
     $post->setTitle('Hello World');
     $post->setContent('This is a hello world post');
     $post->setCreated(new \DateTime());
     $em->persist($post);
     // Create new post log object
     $postLog = new PostLog();
     $postLog->setMessage('A new post was created');
     $postLog->setCreated(new \DateTime());
     $postLog->setParent($post);
     $em->persist($postLog);
     // Try to create a category
     $category = new Category();
     $category->setTitle('A Category');
     $category->setDescription('A category to created');
     $em->persist($category);
     // Create new category log object
     $categoryLog = new CategoryLog();
     $categoryLog->setMessage('A new category was created');
     $categoryLog->setCreated(new \DateTime());
     $categoryLog->setParent($category);
     $em->persist($categoryLog);
     // Actually store all the entities to the database
     // to get id of the post and the category
     $em->flush();
     return ['Done'];
 }
开发者ID:vutung2311,项目名称:sf2_playground,代码行数:39,代码来源:DefaultController.php


示例2: addAction

 /**
  * @Route("/post/add/{id}", name="addPost")
  */
 public function addAction($id, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $topic = $em->getRepository('AppBundle:Topic')->find($id);
     if (!$topic) {
         throw $this->createNotFoundException('No Topic found for id ' . $id);
     }
     $post = new Post();
     $post->setDate(new \DateTime('now'));
     $loggedIn = false;
     $securityContext = $this->container->get('security.authorization_checker');
     if ($securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         $token = $this->get('security.token_storage')->getToken();
         /* @var $user User */
         $user = $token->getUser();
         $post->setAuthor($user);
         $post->setTopic($topic);
         $loggedIn = true;
     }
     $form = $this->createFormBuilder($post)->add('content', TextareaType::class)->add('save', SubmitType::class, array('label' => 'Reply'))->getForm();
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em->persist($post);
         $em->flush();
         return $this->render('Topic/watch.html.twig', array('topic' => $topic, 'form' => $form->createView(), 'loggedIn' => $loggedIn));
     }
     return $this->render('Post/add.html.twig', array('topic' => $topic, 'form' => $form->createView(), 'loggedIn' => $loggedIn));
 }
开发者ID:basti92,项目名称:Qorum,代码行数:31,代码来源:PostController.php


示例3: loadPosts

 private function loadPosts(ObjectManager $manager)
 {
     $passwordEncoder = $this->container->get('security.password_encoder');
     $user = new User();
     $user->setUsername('vvasia');
     $user->setDisplayName('Vasia Vasin');
     $user->setEmail('[email protected]');
     $user->setUuid('uuid');
     $encodedPassword = $passwordEncoder->encodePassword($user, 'password');
     $user->setPassword($encodedPassword);
     $user->setRoles(['ROLE_USER']);
     $manager->persist($user);
     $manager->flush();
     /** @var User $author */
     $author = $manager->getRepository('AppBundle:User')->findOneBy(['email' => '[email protected]']);
     foreach (range(1, 10) as $i) {
         $post = new Post();
         $post->setTitle($this->getRandomPostTitle() . ' ' . uniqid())->setSummary($this->getRandomPostSummary())->setSlug($this->container->get('slugger')->slugify($post->getTitle()))->setContent($this->getPostContent())->setAuthor($author)->setPublishedAt(new \DateTime('now - ' . $i . 'days'))->setState($this->getRandomState())->setCategory($category);
         foreach (range(1, 5) as $j) {
             $comment = new Comment();
             $comment->setUser($user)->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds'))->setContent($this->getRandomCommentContent())->setPost($post);
             $manager->persist($comment);
             $post->addComment($comment);
         }
         if (rand(0, 1)) {
             $vote = new Vote();
             $vote->setAuthorEmail(rand(0, 1) ? '[email protected]' : '[email protected]');
             $vote->setPost($post);
             $vote->setVote(rand(0, 1));
         }
         $manager->persist($post);
         $category->addPost($post);
     }
     $manager->flush();
 }
开发者ID:stanislav-sulima,项目名称:levi9voter,代码行数:35,代码来源:LoadFixtures.php


示例4: createAction

 /**
  * @Route("/create", name="create_post")
  */
 public function createAction(Request $request)
 {
     // just setup a fresh $post object (remove the dummy data)
     $post = new Post();
     $post->setAuthorEmail('[email protected]');
     $form = $this->createForm(new PostType(), $post);
     $finder = new Finder();
     $data = $finder->files()->in($_SERVER['DOCUMENT_ROOT'] . 'Benedictux/web/upload');
     //$data = $this->get('app.scanner')->scanDir($_SERVER['DOCUMENT_ROOT'].'Benedictux/web/uploads');
     //$data = $this->get('app.scanner')->scanDirectory($this->get('request')->getBasePath());
     //$scanned_directory = array_diff(scandir('./web'), array('..', '.'));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $slug = $this->get('app.slugger')->slugify($post->getTitle());
         $post->setSlug($slug);
         if (get_magic_quotes_gpc()) {
             $content = stripslashes($post->getContent());
             $content = $this->get('app.parser')->parserTexarea($content);
             $post->setContent($content);
         } else {
             $content = $this->get('app.parser')->parserTexarea($post->getContent());
             $post->setContent($content);
         }
         $em->persist($post);
         $em->flush();
         return $this->redirectToRoute('accueil');
     }
     return $this->render('app/postCreate.html.twig', array('form' => $form->createView(), 'data' => $data));
 }
开发者ID:Benedictux,项目名称:Benedictux,代码行数:33,代码来源:PostController.php


示例5: newAction

 /**
  * Displays a form to create a new Post entity.
  *
  * @Route("/new", name="admin_post_new")
  * @Method("GET")
  * @Template()
  */
 public function newAction()
 {
     $entity = new Post();
     $entity->setCreatedAt();
     $form = $this->createCreateForm($entity);
     return array('entity' => $entity, 'form' => $form->createView());
 }
开发者ID:KondzioRozpruwacz,项目名称:hotel,代码行数:14,代码来源:PostController.php


示例6: addPostAction

 /**
  * @Route("{page}/temat/{temat}")
  */
 public function addPostAction(Request $request, $temat, $page)
 {
     if ($this->getUser() == true) {
         $task = new Post();
         $task->setAutor($this->getUser()->getUsername());
         $task->setIdTematu($temat);
         $task->setCzasAdd(new \DateTime("now"));
         $form = $this->createFormBuilder($task)->add('Tresc', TextareaType::class)->add('Zapisz', SubmitType::class, array('label' => 'Dodaj'))->getForm();
         $form->handleRequest($request);
         if ($form->isSubmitted() && $form->isValid()) {
             $this->savePost($task);
             $this->upgradePost($page);
         }
         $em = $this->getDoctrine()->getManager();
         $query = $em->createQuery("SELECT u FROM AppBundle:Post u WHERE u.idTematu = :id ");
         $query->setParameter('id', $temat);
         $tematy = $query->getResult();
         $size = sizeof($tematy);
         return $this->render('Posts/post_page.html.twig', array('form' => $form->createView(), 'size' => $size, 'tematy' => $tematy, "page" => $page));
     } else {
         $em = $this->getDoctrine()->getManager();
         $query = $em->createQuery("SELECT u FROM AppBundle:Post u WHERE u.idTematu = :id ");
         $query->setParameter('id', $temat);
         $tematy = $query->getResult();
         $size = sizeof($tematy);
         return $this->render('Posts/post_page.html.twig', array('size' => $size, 'tematy' => $tematy, "page" => $page));
     }
 }
开发者ID:1Shalafi1,项目名称:Forum,代码行数:31,代码来源:PagePostController.php


示例7: blogAction

 /**
  * @Route("/channel/{uniqID}/blog", name="oktothek_series_blog_post")
  * @Method({"GET", "POST"})
  * @Template()
  */
 public function blogAction(Request $request, Series $series)
 {
     $this->denyAccessUnlessGranted('edit_channel', $series);
     $post = new Post();
     $post->setIsActive(true);
     $form = $this->createForm(PostType::class, $post, ['action' => $this->generateUrl('oktothek_series_blog_post', ['uniqID' => $series->getUniqID()])]);
     $form->add('submit', SubmitType::class, ['label' => 'oktothek.post_create_button', 'attr' => ['class' => 'btn btn-primary']]);
     if ($request->getMethod() == "POST") {
         //sends form
         $form->handleRequest($request);
         if ($form->isValid()) {
             $em = $this->getDoctrine()->getManager();
             $series->addPost($post);
             foreach ($post->getAssets() as $asset) {
                 $asset->setSeries($series);
                 $em->persist($asset);
             }
             $em->persist($post);
             $em->persist($series);
             $em->flush();
             $this->get('session')->getFlashBag()->add('success', 'oktothek.success_create_post');
             $this->get('oktothek_notification_service')->createNewPostNotifications($post);
             return $this->redirect($this->generateUrl('oktothek_channel_blogposts', ['uniqID' => $series->getUniqID()]));
         } else {
             $this->get('session')->getFlashBag()->add('error', 'oktothek.error_create_post');
         }
     }
     return ['form' => $form->createView(), 'series' => $series];
 }
开发者ID:OKTOTV,项目名称:FLUX2,代码行数:34,代码来源:ProducerController.php


示例8: canEdit

 private function canEdit(Post $post, UserInterface $user, TokenInterface $token)
 {
     if ($this->decisionManager->decide($token, ['ROLE_MANAGER']) && $post->getOwner() == $user) {
         return true;
     }
     return false;
 }
开发者ID:Wolframcheg,项目名称:symfonyblog,代码行数:7,代码来源:PostVoter.php


示例9: addPost

 public function addPost(Post $post, User $user)
 {
     $post->setAuthor($user);
     $this->em->persist($post);
     $user->setLastPost($post);
     $user->increasePostsCount();
     $this->em->flush();
 }
开发者ID:AeonRush,项目名称:demoblog,代码行数:8,代码来源:PostManager.php


示例10: save

 public function save(Post $entity)
 {
     $entity->setUpdated(date_create());
     $entityManager = $this->getEntityManager();
     $entityManager->persist($entity);
     $entityManager->flush();
     return $entity;
 }
开发者ID:tuimedia,项目名称:forum,代码行数:8,代码来源:PostRepository.php


示例11: delete

 /**
  * @return int
  */
 public function delete(User $user, Post $post)
 {
     $conn = $this->_em->getConnection();
     $statement = $conn->prepare('DELETE FROM post_vote WHERE user_id = :user_id AND post_id = :post_id');
     $statement->bindValue('user_id', $user->getId());
     $statement->bindValue('post_id', $post->getId());
     return $statement->execute();
 }
开发者ID:matheusgontijo,项目名称:MageBrazuca,代码行数:11,代码来源:PostVoteRepository.php


示例12: createBlogAction

 /**
  * @Route("/create-blog", name="create-blog")
  */
 public function createBlogAction(Request $request)
 {
     $post = new Post();
     $post->setDescription('Nuevo post');
     $em = $this->getDoctrine()->getManager();
     $em->persist($post);
     $em->flush();
     return new Response('Created post id ' . $post->getId());
 }
开发者ID:lokitold,项目名称:symfony16,代码行数:12,代码来源:TestDoctrineController.php


示例13: canEdit

 private function canEdit(Post $post, User $user)
 {
     // this assumes that the data object has a getOwner() method
     // to get the entity of the user who owns this data object
     //if ($post->getAuthor()->getIsAdmin() and !$user->getIsAdmin()) {
     //    return false;
     //}
     return $user === $post->getAuthor() or $user->getIsAdmin();
 }
开发者ID:maximzh,项目名称:Blog,代码行数:9,代码来源:PostVoter.php


示例14: createAction

 /**
  * Creates a new Post entity.
  *
  * @Route("/", name="post_create")
  * @Method("POST")
  */
 public function createAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $post = new Post();
     $post->setContent($request->getContent());
     $em->persist($post);
     $em->flush();
     return new JsonResponse();
 }
开发者ID:CochicerrosDev,项目名称:symfony-react-edition,代码行数:15,代码来源:PostController.php


示例15: load

 public function load(ObjectManager $manager)
 {
     $repo = new Post();
     $repo->setTitle('Post title 1');
     $manager->persist($repo);
     $repo = new Post();
     $repo->setTitle('Post title 2');
     $manager->persist($repo);
     $manager->flush();
 }
开发者ID:riskawarrior,项目名称:Symfony-for-CD,代码行数:10,代码来源:LoadPosts.php


示例16: 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


示例17: newAction

 /**
  * @Route("/new")
  * @Method({"GET"})
  */
 public function newAction()
 {
     $post = new Post();
     $categories = $this->getDoctrine()->getRepository('AppBundle:Category')->findAll();
     foreach ($categories as $category) {
         $post->addCategory($category);
     }
     $form = $this->createForm(new PostType(), $post);
     return $this->render('Admin/new.html.twig', ['form' => $form->createView()]);
 }
开发者ID:ryota-murakami,项目名称:symfony-blog-sample,代码行数:14,代码来源:AdminController.php


示例18: load

 public function load(ObjectManager $manager)
 {
     foreach ($this->getData() as $payload) {
         $post = new Entity\Post();
         $post->setTitle($payload[0]);
         $post->setContent($payload[1]);
         $post->setCreated($payload[2]);
         $manager->persist($post);
     }
     $manager->flush();
 }
开发者ID:Wobbly-Wibbly,项目名称:sfTestProject,代码行数:11,代码来源:Post.php


示例19: testSetUser

 public function testSetUser()
 {
     // new entity
     $post = new Post();
     // dummy entity
     $user = new User();
     $user->setFirstName("Ole");
     // Use the setUser method
     $post->setUser($user);
     // Assert the result
     $this->assertEquals($user, $post->getUser());
 }
开发者ID:vegardbb,项目名称:webpage,代码行数:12,代码来源:PostEntityUnitTest.php


示例20: sendPostVoteClosedEmail

 /**
  * Send email to author and all people from comments when vote is Approved or Rejected
  *
  * @param Post   $post
  * @param string $translation
  * @param string $template
  */
 private function sendPostVoteClosedEmail(Post $post, $translation, $template)
 {
     $recipients[] = $post->getAuthor()->getEmail();
     /** @var Comment $comment */
     $comments = $post->getComments();
     foreach ($comments as $comment) {
         $recipients[] = $comment->getUser()->getEmail();
     }
     $subject = $this->translator->trans($translation);
     $body = $this->renderView($template, array('post' => $post));
     $this->mailer->send($recipients, $subject, $body);
 }
开发者ID:MykolaBova,项目名称:levi9voter,代码行数:19,代码来源:PostNotifier.php



注:本文中的AppBundle\Entity\Post类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Entity\User类代码示例发布时间:2022-05-23
下一篇:
PHP services\Config类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap