title: How can I send a parameter into custom repository method in Symfony2?
body: <p>OK, so I want to send a currently logged in user to my custom method in ProductRepository, that will filter the products for the ones that are assigned to this user. My product.yml route to the listing of products:</p>
  
  <pre><code>sylius_backend_product_index:
  pattern: /
  methods: [GET]
  defaults:
      _controller: sylius.controller.product:indexAction
      _sylius:
          template: SyliusWebBundle:Backend/Product:index.html.twig
          method: createFilterPaginator2
          arguments: [$criteria, $sorting, $deleted, $user]
  </code></pre>
  
  <p>Next I go to the controller, ProductController does not have the indexAction method, but its extension ResourceController has, the index action:</p>
  
  <pre><code> public function indexAction(Request $request)
  {
      $criteria = $this-&gt;config-&gt;getCriteria();
      $sorting = $this-&gt;config-&gt;getSorting();
      $user = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser();
  
      $repository = $this-&gt;getRepository();
  
      if ($this-&gt;config-&gt;isPaginated()) {
          $resources = $this-&gt;resourceResolver-&gt;getResource(
              $repository,
              'createFilterPaginator2',
              array($criteria, $sorting, false, $user)
          );
          $resources-&gt;setCurrentPage($request-&gt;get('page', 1), true, true);
          $resources-&gt;setMaxPerPage($this-&gt;config-&gt;getPaginationMaxPerPage());
  
          if ($this-&gt;config-&gt;isApiRequest()) {
              $resources = $this-&gt;getPagerfantaFactory()-&gt;createRepresentation(
                  $resources,
                  new Route(
                      $request-&gt;attributes-&gt;get('_route'),
                      $request-&gt;attributes-&gt;get('_route_params')
                  )
              );
          }
      } else {
          $resources = $this-&gt;resourceResolver-&gt;getResource(
              $repository,
              'findBy',
              array($criteria, $sorting, $this-&gt;config-&gt;getLimit(), $user)
          );
      }
  
      $view = $this
          -&gt;view()
          -&gt;setTemplate($this-&gt;config-&gt;getTemplate('index.html'))
          -&gt;setTemplateVar($this-&gt;config-&gt;getPluralResourceName())
          -&gt;setData($resources)
      ;
  
      return $this-&gt;handleView($view);
  }
  </code></pre>
  
  <p>Here I added the</p>
  
  <pre><code> $user = $this-&gt;get('security.context')-&gt;getToken()-&gt;getUser();
  </code></pre>
  
  <p>and then added $user to the parameters array for the $resources. 
  The createFilterPaginator2 method itself looks like :</p>
  
  <pre><code> public function createFilterPaginator2($criteria = array(), $sorting = array(), $deleted = false, UserInterface $user = NULL)
  {
      $queryBuilder = parent::getCollectionQueryBuilder()
          -&gt;select('product, variant')
          -&gt;leftJoin('product.variants', 'variant')
          -&gt;where('product.seller = :user')
          -&gt;setParameter('user', $user)
      ;
  
      //var_dump($user-&gt;getUsername());
      if (!empty($criteria['name'])) {
          $queryBuilder
              -&gt;andWhere('product.name LIKE :name')
              -&gt;setParameter('name', '%'.$criteria['name'].'%')
          ;
      }
      if (!empty($criteria['sku'])) {
          $queryBuilder
              -&gt;andWhere('variant.sku = :sku')
              -&gt;setParameter('sku', $criteria['sku'])
          ;
      }
  
      if (empty($sorting)) {
          if (!is_array($sorting)) {
              $sorting = array();
          }
          $sorting['updatedAt'] = 'desc';
      }
  
      $this-&gt;applySorting($queryBuilder, $sorting);
  
      if ($deleted) {
          $this-&gt;_em-&gt;getFilters()-&gt;disable('softdeleteable');
      }
  
      return $this-&gt;getPaginator($queryBuilder);
  }
  </code></pre>
  
  <p>And the problem is that in the ResourceController my $user correctly returns current logged in user, but the $user isn't successfully sent to the method. I believe I'm missing sth important, my guess would be that the arguments: [$criteria, $sorting, $deleted, $user] shouldn't be returned by the ResourceController, but I have no better idea atm.</p>
  
  <p>I would appreciate any help, on how to send parameters to the custom repository methods, useful links etc. Thanks !</p>