title: How do I get total count for a search query in the controller in Symfony
body: <p><strong>Use case</strong>: I want to store the search query and the total number of results to the db so I can see what people are searching for that doesn't exist in my application.</p>
  
  <p><strong>What is working</strong>: I'm able to get and store the query, but I can't figure out how to get the total number of results for the search. </p>
  
  <p>Here is the code sample from the Controller. When I try this currently, I get the following </p>
  
  <blockquote>
    <p>error:Catchable Fatal Error: Object of class
    Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination could not be
    converted to string</p>
  </blockquote>
  
  <p>I've tried treating $pagination like an array, by requesting $pagination[totalCount], but that just returned null. </p>
  
  <pre><code> public function fpcAction(Request $request)
      {
  
              $query = dump($request-&gt;query-&gt;get('q'));
  
              $finder = $this-&gt;container-&gt;get('fos_elastica.finder.app.product');
              $page = $request-&gt;query-&gt;getInt('page', 1);
  
              $paginator = $this-&gt;get('knp_paginator');
              $results = $finder-&gt;createPaginatorAdapter($query);
              $pagination = $paginator-&gt;paginate($results, $page, 12);
  
  
  
              $searchmetrics = new SearchTerms();
              $searchmetrics-&gt;setSearchterm($query);
              $searchmetrics-&gt;setDate(time());
  
              // TODO: Need to get the total qty of search results for this specific query
              $searchmetrics-&gt;setResultsqty($pagination);
  
              $entityManager = $this-&gt;getDoctrine()-&gt;getManager();
              $entityManager-&gt;persist($searchmetrics);
              $entityManager-&gt;flush();
  
  
              return $this-&gt;render('default/search.html.twig', ['searchresults' =&gt; $pagination, 'query' =&gt; $query]);
  
      }
  </code></pre>
  
  <p>Here is a dump of the variable as it outputs on the twig template:</p>
  
  <pre><code> "searchresults" =&gt; SlidingPagination {#1028 ▼
      -route: "search"
      -params: array:1 [▶]
      -pageRange: 5
      -template: "@KnpPaginator/Pagination/sliding.html.twig"
      -sortableTemplate: "@KnpPaginator/Pagination/sortable_link.html.twig"
      -filtrationTemplate: "@KnpPaginator/Pagination/filtration.html.twig"
      #currentPageNumber: 1
      #numItemsPerPage: 12
      #items: array:12 [▶]
      #totalCount: 8104
      #paginatorOptions: array:6 [▶]
      #customParameters: []
    }
  </code></pre>