title: Symfony search-box issue
body: <p>I've an issue to make a search-box with Symfony and Doctrine. I use the 2.8 version of Symfony.</p>
  
  <p>My issue is : </p>
  
  <blockquote>
    <p>EntityManager#persist() expects parameter 1 to be an entity object, array given. 500 Internal Server Error - ORMInvalidArgumentException</p>
  </blockquote>
  
  <p>So, this is my Type for my search-box type :</p>
  
  <pre><code>/**
   * {@inheritdoc}
   */
  public function buildForm(FormBuilderInterface $builder, array $options)  {
  
      $builder-&gt;add('searchBox',SearchType::class,array('label'=&gt;'Vous cherchez : Un auteur ? Un éditeur ? Un ouvrage ?','attr'=&gt;array('class'=&gt;'form-control')));
  
  }
  
  /**
   * {@inheritdoc}
   */
  public function configureOptions(OptionsResolver $resolver)
  {
      $resolver-&gt;setDefaults(array(
          'data_class1' =&gt; 'SB\MainBundle\Entity\Ouvrages',
          'data_class2' =&gt; 'SB\MainBundle\Entity\Auteurs',
          'data_class3' =&gt; 'SB\MainBundle\Entity\Editeurs'
      ));
  }
  </code></pre>
  
  <p>And this is my controller code after edit :</p>
  
  <pre><code>public function indexAction(Request $request) {
      $ouvragesVentes = $this-&gt;getDoctrine()-&gt;getRepository('SBMainBundle:Ouvrages')-&gt;getOuvragesVentes();
      $ouvragesEchanges = $this-&gt;getDoctrine()-&gt;getRepository('SBMainBundle:Ouvrages')-&gt;getOuvragesEchanges();
      $categories = $this-&gt;getDoctrine()-&gt;getRepository('SBMainBundle:Categories')-&gt;getAllCats();
  
      $form = $this-&gt;createForm(SearchBoxType::class);
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
  
          $searchBoxValue = $form-&gt;getData();
  
          $bookName = $this-&gt;getDoctrine()-&gt;getRepository('SBMainBundle:Ouvrages')-&gt;getOuvrageName($searchBoxValue);
          $editorName = $this-&gt;getDoctrine()-&gt;getRepository('SBMainBundle:Editeurs')-&gt;getEditeurName($searchBoxValue);
          $autorName = $this-&gt;getDoctrine()-&gt;getRepository('SBMainBundle:Auteurs')-&gt;getAuteurName($searchBoxValue);
  
          //if author
          if ($searchBoxValue == $autorName){
              return $this-&gt;redirect($this-&gt;generateUrl('sb_main_auteur'));
          }
          //if editor
          if ($searchBoxValue == $editorName){
              return $this-&gt;redirect($this-&gt;generateUrl('sb_main_editeur'));
          }
          //if book name
          if ($searchBoxValue == $bookName){
              return $this-&gt;redirect($this-&gt;generateUrl('sb_main_ouvrage'));
          }
      }
  
      $datas = array('categories'=&gt;$categories,'form'=&gt;$form-&gt;createView(),'ouvragesEchanges'=&gt;$ouvragesEchanges,'ouvragesVentes'=&gt;$ouvragesVentes);
      return $this-&gt;render('SBMainBundle:Main:index.html.twig',$datas);
  }
  </code></pre>
  
  <p>Edit : My formHandler</p>
  
  <pre><code>    protected $request;
  protected $form;
  protected $em;
  
  
  //faire une injection de dépendance avec Request,Manager,Form(Objet)
  public function __construct(Request $request,EntityManager $em, Form $form){
      $this-&gt;request = $request;
      $this-&gt;em = $em;
      $this-&gt;form = $form;
  }
  
  //vérifie si le formulaire est soumis et valide
  public function process(){
  
      if ($this-&gt;request-&gt;getMethod() == "POST"){
          //récupération des données de la requête de la superglobale $_POST
          $this-&gt;form-&gt;handleRequest($this-&gt;request);
          //si ok, on appel onSuccess()
          if ($this-&gt;form-&gt;isValid()){
              $this-&gt;onSuccess($this-&gt;form-&gt;getData());
              return true;
          }
      }
      return false;
  
  }
  
  //si formulaire soumis et valide, on presiste l'objet (enregistre dans la DB)
  public function onSuccess($object){
      //on persiste dans la DB via le manager Doctrine
      $this-&gt;em-&gt;persist($object);
      $this-&gt;em-&gt;flush();
  }
  </code></pre>
  
  <p>I've look <a href="https://stackoverflow.com/questions/17681531/symfony2-entitymanagerpersist-expects-parameter-1-to-be-an-entity-object-arr">here</a> but I think is not the solution of my issue. Then, someone can tell me what is wrong ? Do I need a search-box entity even with a search-box ? </p>
  
  <p>Thanks for your help !</p>
  
  <p>Edit :</p>
  
  <p>Stack Trace</p>
  
  <pre><code>in src\SB\MainBundle\Repository\OuvragesRepository.php at line 130   -
  
  public function getOuvrageName($titre){
      $query = $this-&gt;getEntityManager()-&gt;createQuery(
          "SELECT o FROM SBMainBundle:Ouvrages o WHERE o.titreOuvrage = $titre ORDER BY o.id DESC "
      );
      return $query-&gt;getResult();
  
  
  at ErrorHandler -&gt;handleError ('8', 'Array to string conversion',     'C:\wamp\www\switchbook\src\SB\MainBundle\Repository\OuvragesRepository.php', '130', array('titre' =&gt; array('searchBox' =&gt; 'flammarion'))) 
  in src\SB\MainBundle\Repository\OuvragesRepository.php at line 130   +
  at OuvragesRepository -&gt;getOuvrageName (array('searchBox' =&gt; 'flammarion')) 
  in src\SB\MainBundle\Controller\MainController.php at line 35   +
  at MainController -&gt;indexAction (object(Request))
  at call_user_func_array (array(object(MainController), 'indexAction'),   array(object(Request))) 
  in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 144   +
  at HttpKernel -&gt;handleRaw (object(Request), '1') 
  </code></pre>
  
  <p>in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 64   +
      at HttpKernel ->handle (object(Request), '1', true) 
  in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel.php at line 69   +
      at ContainerAwareHttpKernel ->handle (object(Request), '1', true) 
      in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php     at line 185   +
      at Kernel ->handle (object(Request)) 
      in web\app_dev.php at line 28   +</p>
  
  <p>New Edit :</p>
  
  <blockquote>
    <p>Some mandatory parameters are missing ("titreOuvrage") to generate a URL for route "sb_main_ouvrage".</p>
  </blockquote>
  
  <pre><code>sb_main_ouvrage:
  path:     /ouvrage/{titreOuvrage}
  defaults: { _controller: SBMainBundle:Main:ouvrage}
  </code></pre>
  
  <p>Stack Trace</p>
  
  <p>in app\cache\dev\classes.php at line 911</p>
  
  <pre><code>$variables = array_flip($variables);
  $mergedParams = array_replace($defaults, $this-&gt;context-&gt;getParameters(), $parameters);
  if ($diff = array_diff_key($variables, $mergedParams)) {throw new MissingMandatoryParametersException(sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".', implode('", "', array_keys($diff)), $name));}
  $url ='';
  $optional = true;
  
  at UrlGenerator -&gt;doGenerate (array('titreOuvrage'), array('_controller' =&gt; 'SB\MainBundle\Controller\MainController::ouvrageAction'), array(), array(array('variable', '/', '[^/]++', 'titreOuvrage'), array('text', '/ouvrage')), array(), 'sb_main_ouvrage', '1', array(), array()) 
  in app\cache\dev\appDevDebugProjectContainerUrlGenerator.php at line 92   +
  at appDevDebugProjectContainerUrlGenerator -&gt;generate ('sb_main_ouvrage', array(), '1') 
  in app\cache\dev\classes.php at line 1286   +
  at Router -&gt;generate ('sb_main_ouvrage', array(), '1') 
  in vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php at line 52   +
  at Controller -&gt;generateUrl ('sb_main_ouvrage') 
  in src\SB\MainBundle\Controller\MainController.php at line 49   +
  at MainController -&gt;indexAction (object(Request))
  at call_user_func_array (array(object(MainController), 'indexAction'), array(object(Request))) 
  in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 144   +
  at HttpKernel -&gt;handleRaw (object(Request), '1') 
  in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 64   +
  at HttpKernel -&gt;handle (object(Request), '1', true) 
  in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel.php at line 69   +
  at ContainerAwareHttpKernel -&gt;handle (object(Request), '1', true) 
  in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php at line 185   +
  at Kernel -&gt;handle (object(Request)) 
  in web\app_dev.php at line 28
  </code></pre>
  
  <p>And my controller for the mapping page :</p>
  
  <pre><code>    public function ouvrageAction(Ouvrages $ouvrages){
      $ouvrage =  $ouvrages-&gt;getTitreOuvrage();
      $categories = $this-&gt;getDoctrine()-&gt;getRepository('SBMainBundle:Categories')-&gt;getAllCats();
      $ouvragesVentes = $this-&gt;getDoctrine()-&gt;getRepository('SBMainBundle:Ouvrages')-&gt;getOuvragesVentesByName($ouvrage);
      $ouvragesEchanges = $this-&gt;getDoctrine()-&gt;getRepository('SBMainBundle:Ouvrages')-&gt;getOuvragesEchangesByName($ouvrage);
      $datas = array('ouvragesVentes'=&gt;$ouvragesVentes,'ouvragesEchanges'=&gt;$ouvragesEchanges,'categories'=&gt;$categories,'ouvrages'=&gt;$ouvrages);
      return $this-&gt;render('SBMainBundle:Main:ouvrage.html.twig',$datas);
  }
  </code></pre>