Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何调试Symfony/Twig加载页面中的“警告:preg_match()期望参数2为字符串,对象给定”?_Symfony_Twig - Fatal编程技术网

如何调试Symfony/Twig加载页面中的“警告:preg_match()期望参数2为字符串,对象给定”?

如何调试Symfony/Twig加载页面中的“警告:preg_match()期望参数2为字符串,对象给定”?,symfony,twig,Symfony,Twig,usilizateurtype.php {%block body%} 利用者名单 每次尝试加载页面时,都会出现此错误。在我将某些内容添加到数据库之前,它工作得很好,一旦添加,我就会遇到问题: 警告:preg_match期望参数2为字符串,对象给定 然后当我刷新时,我得到第二个错误 我认为你需要通过一个个人身份证,如果我没有弄错的话,你的身份证应该是这样的: <a href="{{ path('utilisateur_show', { 'id': utilisateur.idpersonne

usilizateurtype.php

{%block body%} 利用者名单

每次尝试加载页面时,都会出现此错误。在我将某些内容添加到数据库之前,它工作得很好,一旦添加,我就会遇到问题:

警告:preg_match期望参数2为字符串,对象给定

然后当我刷新时,我得到第二个错误


我认为你需要通过一个个人身份证,如果我没有弄错的话,你的身份证应该是这样的:

<a href="{{ path('utilisateur_show', { 'id': utilisateur.idpersonne.idpersonne }) }}">
{{ dump(utilisateur.idpersonne) }}

请写下你的问题,并重新写下你的标题来描述你的实际问题。请重新写下你的标题来描述你的实际问题,正如@Blorgbeard所问的那样。我需要帮助,请…我不明白这不是一个有用的标题。错误是非常不言自明的,但是index.html.twig中第18行的内容是什么?你提到了第二个错误,但就我所知,你只给出了其中一个错误的文本。您遇到的另一个错误是什么?
<?php

  namespace biblioBundle\Controller;

  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;

  use biblioBundle\Entity\Utilisateur;
  use biblioBundle\Form\UtilisateurType;

  /**
   * Utilisateur controller.
   *
   */
  class UtilisateurController extends Controller
  {
/**
 * Lists all Utilisateur entities.
 *
 */
public function indexAction()
{
    $em = $this->getDoctrine()->getManager();

    $utilisateurs = $em->getRepository('biblioBundle:Utilisateur')->findAll();

    return $this->render('utilisateur/index.html.twig', array(
        'utilisateurs' => $utilisateurs,
    ));
}

/**
 * Creates a new Utilisateur entity.
 *
 */
public function newAction(Request $request)
{
    $utilisateur = new Utilisateur();
    $form = $this->createForm('biblioBundle\Form\UtilisateurType', $utilisateur);
    $form->handleRequest($request);

    if ($form->isSubmitted() && $form->isValid()) {
        $em = $this->getDoctrine()->getManager();
        $em->persist($utilisateur);
        $em->flush();

        return $this->redirectToRoute('utilisateur_show', array('id' => $utilisateur->getIdpersonne()));
    }

    return $this->render('utilisateur/new.html.twig', array(
        'utilisateur' => $utilisateur,
        'form' => $form->createView(),
    ));
}

/**
 * Finds and displays a Utilisateur entity.
 *
 */
public function showAction(Utilisateur $utilisateur)
{
    $deleteForm = $this->createDeleteForm($utilisateur);

    return $this->render('utilisateur/show.html.twig', array(
        'utilisateur' => $utilisateur,
        'delete_form' => $deleteForm->createView(),
    ));
}

/**
 * Displays a form to edit an existing Utilisateur entity.
 *
 */
public function editAction(Request $request, Utilisateur $utilisateur)
{
    $deleteForm = $this->createDeleteForm($utilisateur);
    $editForm = $this->createForm('biblioBundle\Form\UtilisateurType', $utilisateur);
    $editForm->handleRequest($request);

    if ($editForm->isSubmitted() && $editForm->isValid()) {
        $em = $this->getDoctrine()->getManager();
        $em->persist($utilisateur);
        $em->flush();

        return $this->redirectToRoute('utilisateur_edit', array('id' => $utilisateur->getIdpersonne()));
    }

    return $this->render('utilisateur/edit.html.twig', array(
        'utilisateur' => $utilisateur,
        'edit_form' => $editForm->createView(),
        'delete_form' => $deleteForm->createView(),
    ));
}

/**
 * Deletes a Utilisateur entity.
 *
 */
public function deleteAction(Request $request, Utilisateur $utilisateur)
{
    $form = $this->createDeleteForm($utilisateur);
    $form->handleRequest($request);

    if ($form->isSubmitted() && $form->isValid()) {
        $em = $this->getDoctrine()->getManager();
        $em->remove($utilisateur);
        $em->flush();
    }

    return $this->redirectToRoute('utilisateur_index');
}

/**
 * Creates a form to delete a Utilisateur entity.
 *
 * @param Utilisateur $utilisateur The Utilisateur entity
 *
 * @return \Symfony\Component\Form\Form The form
 */
private function createDeleteForm(Utilisateur $utilisateur)
{
    return $this->createFormBuilder()
        ->setAction($this->generateUrl('utilisateur_delete', array('id' => $utilisateur->getIdpersonne())))
        ->setMethod('DELETE')
        ->getForm()
    ;
}
  }
{% extends 'base.html.twig' %}
<table>
    <thead>
        <tr>
            <th>Ncin</th>
            <th>Pseudo</th>
            <th>Motdepasse</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
    {% for utilisateur in utilisateurs %}
        <tr>
            <td><a href="{{ path('utilisateur_show', { 'id': utilisateur.idpersonne }) }}">{{ utilisateur.ncin }}</a></td>
            <td>{{ utilisateur.pseudo }}</td>
            <td>{{ utilisateur.motdepasse }}</td>
            <td>
                <ul>
                    <li>
                        <a href="{{ path('utilisateur_show', { 'id': utilisateur.idpersonne }) }}">show</a>
                    </li>
                    <li>
                        <a href="{{ path('utilisateur_edit', { 'id': utilisateur.idpersonne }) }}">edit</a>
                    </li>
                </ul>
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>

<ul>
    <li>
        <a href="{{ path('utilisateur_new') }}">Create a new entry</a>
    </li>
</ul>
  {% endblock %}
<a href="{{ path('utilisateur_show', { 'id': utilisateur.idpersonne.idpersonne }) }}">
{{ dump(utilisateur.idpersonne) }}