Advertisement
Device-Cheat

symfony postrepository

Apr 24th, 2020
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. // src/BlobBundle/Repository/PostRepository.php
  3. namespace BlogBundle\Repository;
  4.  
  5. use BlogBundle\Entity\Post;
  6. use Doctrine\ORM\EntityRepository;
  7.  
  8. class PostRepository extends EntityRepository
  9. {
  10.     /**
  11.      * Store post to database
  12.      *
  13.      * @param Post $post
  14.      */
  15.     public function persist(Post $post)
  16.     {
  17.         $this->getEntityManager()->persist($post);
  18.         $this->getEntityManager()->flush();
  19.     }
  20.  
  21.     /**
  22.      * Search posts with given author's name
  23.      *
  24.      * @param string $name
  25.      * @return array
  26.      */
  27.     public function findByAuthorName($name)
  28.     {
  29.         return $this->createQueryBuilder('posts')
  30.             ->select('posts')
  31.             ->join('posts.author', 'author')
  32.             ->where('author.name = :name')
  33.             ->setParameter('name', $name)
  34.             ->getQuery()
  35.             ->getResult();
  36.     }
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43. http://github.com/shfx17
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement