title: Symfony2 How to find records which starts with specified character?
body: <p>How to find records which starts with specified character?</p>
  
  <p>for example: only users where username starts with the A</p>
  
  <p>User class</p>
  
  <pre><code>    &lt;?php
  
      namespace DemoBundle\Entity;
  
      use FOS\UserBundle\Model\User as BaseUser;
      use Doctrine\ORM\Mapping as ORM;
  
      /**
       * @ORM\Entity
       * @ORM\Table(name="fos_user")
       */
      class User extends BaseUser
      {
  
          /**
           * @ORM\Id
           * @ORM\Column(type="integer")
           * @ORM\GeneratedValue(strategy="AUTO")
           */
          protected $id;
  
          /**
           * @ORM\Column(type="string", length=50)
           */
          protected $name;
  
          /**
           * @ORM\Column(type="string", length=50)
           */
          protected $lastname;
  
          public function __construct()
          {
              parent::__construct();
              // your own logic
          }
    //getters and setters
      }
  </code></pre>
  
  <p>and controller action with solution @Kwido</p>
  
  <pre><code>public function listAction($letter)
      {
          $queryBuilder = $this-&gt;getEntityManager()-&gt;createQueryBuilder();
          $queryBuilder
              -&gt;select(['user'])
              -&gt;from(User::class, 'user')
              -&gt;andWhere($queryBuilder-&gt;expr()-&gt;like('user.lastname', ':lastname'))
              -&gt;setParameter('lastname', $queryBuilder-&gt;expr()-&gt;literal('A%'));
  
          $result = $queryBuilder-&gt;getQuery()-&gt;getResult();
  
          die(var_dump($result));
  }
  </code></pre>
  
  <p>this is all what I have. This give me error</p>
  
  <blockquote>
    <p>Attempted to call an undefined method named "getEntityManager" of
    class DemoBundle\Controller\DefaultController"</p>
  </blockquote>