title: Object of class could not be converted to string Symfony2 error
body: <p>I get this error:</p>
  
  <p>An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class Mihail\SearchBundle\Entity\FileSearch could not be converted to string") in form_div_layout.html.twig at line 13.</p>
  
  <p>Using symfony 2.8LTS.
  Here are the files I am using to basically create a search form in my own bundle, that searches in app directory, based on what search criteria is provided in the form. 
  <strong>Search Controller:</strong></p>
  
  <pre><code>&lt;?php
  
   namespace Mihail\SearchBundle\Controller;
  
   use Symfony\Bundle\FrameworkBundle\Controller\Controller;
   use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
   use Mihail\SearchBundle\Entity\FileSearch;
   use Symfony\Component\Finder\Finder;
   use Symfony\Component\HttpFoundation\Request;
   use Mihail\SearchBundle\Form\Type\SearchType;
  
   class SearchController extends Controller
   {
       /**
        * @Route("/search")
        */
       public function searchAction(Request $request)
       {
           $search = new FileSearch();
  
          $dirsList = $this-&gt;generateDirsList();
  
           $form = $this-&gt;createForm(SearchType::class, $search, array('dirs_list' =&gt; $dirsList));
  
           $form-&gt;handleRequest($request);
  
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
              $searchContent = $form-&gt;get('searchContent')-&gt;getData();
              $fileType = $form-&gt;get('fileType')-&gt;getData();
              $searchDir = $form-&gt;get('searchDir')-&gt;getData();
  
              $finder = new Finder();
              if(isset($fileType))
              {
                  $finder-&gt;files()-&gt;name("*.$fileType");
              }
  
              if(isset($searchDir))
              {
                  $finder-&gt;files()-&gt;in($searchDir);
              }else{
                  $finder-&gt;files()-&gt;in(__DIR__);
              }
  
              if(isset($searchContent))
              {
                  $finder-&gt;contains($searchContent);
              }
  
              if(isset($finder) &amp;&amp; count($finder)&gt;0)
              {
                  echo "Found results in $searchDir: &lt;br/&gt;";
                  foreach ($finder as $key =&gt; $value) {
                      echo "&lt;h4&gt; $value contains '$searchContent' &lt;/h4&gt;";
                  }
              }else{
                  echo "No content '$searchContent' in '$searchDir'";
              }
          }
  
           return $this-&gt;render('MihailSearchBundle:randomsearch:search_form.html.twig', array(
               'form' =&gt; $form-&gt;createView(),
           ));
       }
  
       public function generateDirsList()
       {
          $path = $this-&gt;get('kernel')-&gt;getRootDir();
          $finder = new Finder();
  
          $iterator = $finder
              -&gt;ignoreUnreadableDirs()
              -&gt;directories()
              -&gt;depth('&lt; 2')
              -&gt;in($path);
  
          $dirsList = array();
          foreach ($iterator as $key =&gt; $value) {
              $dirsList["$value"] = "$value";
          }
  
          return $dirsList;
       }
   }
  </code></pre>
  
  <p><strong>File Search Fields get and set</strong></p>
  
  <pre><code>&lt;?php
  
   namespace Mihail\SearchBundle\Entity;
  
   use Symfony\Component\Validator\Constraints as Assert;
  
   class FileSearch
   {
  
      protected $searchContent;
  
      protected $fileType;
  
      protected $searchDir;
  
      public function getSearchContent()
       {
           return $this-&gt;searchContent;
       }
  
       public function setSearchContent($searchContent)
       {
           $this-&gt;searchContent = $searchContent;
       }
  
       public function getFileType()
       {
          return $this-&gt;fileType;
       }
  
       public function setFileType($fileType)
       {
          $this-&gt;fileType = $fileType;
       }
  
       public function getSearchDir()
       {
          return $this-&gt;searchDir;
       }
  
       public function setSearchDir($searchDir)
       {
          $this-&gt;searchDir = $searchDir;
       }
   } 
  </code></pre>
  
  <p><strong>Search type for creating the form</strong></p>
  
  <pre><code>&lt;?php
  
   namespace Mihail\SearchBundle\Form\Type;
  
   use Symfony\Component\Form\AbstractType;
   use Symfony\Component\Form\FormBuilderInterface;
   use Symfony\Component\Form\Extension\Core\Type\TextType;
   use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
   use Symfony\Component\Form\Extension\Core\Type\SubmitType;
   use Symfony\Component\OptionsResolver\OptionsResolver;
  
   class SearchType extends AbstractType
   {
      public function buildForm(FormBuilderInterface $builder, array $options)
       {
           $builder
               -&gt;add('searchContent', TextType::class, array('label'=&gt; 'Search Content:* '))
               -&gt;add('fileType', TextType::class , array('label'=&gt; 'File Type:'))
               -&gt;add('searchDir',  ChoiceType::class, array(
                  'label' =&gt; 'Search Path:',
                  'choices' =&gt; $options['dirs_list'],
                  'choices_as_values' =&gt; true))
               -&gt;add('save', SubmitType::class, array('label' =&gt; 'Search for File'));
       }
  
       public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setRequired(array(
              'dirs_list',
          ));
  
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'Mihail\SearchBundle\Entity\FileSearch',
              'dirs_list' =&gt; null,
          ));
      }
   } 
  </code></pre>
  
  <p><strong>A simple twig template to render the form fields</strong></p>
  
  <pre><code>{# Mihail/SearchBudnle/Resources/views/randomsearch/search_form.html.twig #}
  
      {{ form(form, {'attr': {'novalidate': 'novalidate'}}) }}
      {{ form_start(form) }}
          {{ form_row(form.fileType) }}
          {{ form_row(form.searchContent) }}
          {{ form_row(form.searchDir) }}
      {{ form_end(form) }}
  </code></pre>
  
  <p>Any ideas what I'm doing wrong?</p>