简体   繁体   中英

special caracters doesn't working in php symfony twig program

I have a problem with special characters in my symfony program, I usually save my pages with UTF-8 without BOM (I use notepad++) for exemple this page is displayed correcly :

    je suis lé
<h1>Ajouter un acteur</h1>
{% if message %}
<p>{{ message }}</p>
{% endif %}
<form action="" method="post" {{ form_enctype(form) }}>
    {{ form_widget(form) }}
    <input type="submit" />
</form>
<p><a href="{{ path('myapp_acteur_lister') }}">Retour à la liste des acteurs</a></p>

this line je suis lé is displayed well but when I execute a controller function which return a string , this string is not displayed well : here is the function :

public function editerAction($id = null)
{
     $message='';
     $em = $this->container->get('doctrine')->getEntityManager();
     if (isset($id)) 
     {
      // modification d'un acteur existant : on recherche ses données
      $acteur = $em->find('MyAppFilmothequeBundle:Acteur', $id);
      if (!$acteur)
      {
       $message='Aucun acteur trouvé';
      }
     }
     else 
     {
      // ajout d'un nouvel acteur
      $acteur = new Acteur();
     }
     $form = $this->container->get('form.factory')->create(new ActeurForm(), $acteur);
     $request = $this->container->get('request');
     if ($request->getMethod() == 'POST') 
     {
            $form->bindRequest($request);
     if ($form->isValid()) 
     {
      $em->persist($acteur);
      $em->flush();
      if (isset($id)) 
      {
       $message='Acteur modifié avec succès !';
      }
      else 
      {
       $message='Acteur ajouté avec succès !';
      }
     }
     }
     return $this->container->get('templating')->renderResponse(
    'MyAppFilmothequeBundle:Acteur:editer.html.twig',
     array(
     'form' => $form->createView(),
     'message' => $message,
     ));
}

here is the capture of the page :

在此处输入图片说明

how can I achieve this?

确保控制器php文件也使用UTF-8保存。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM