gpt4 book ai didi

php - 交响乐 : preg_match() expecting parameter

转载 作者:行者123 更新时间:2023-11-28 02:47:10 29 4
gpt4 key购买 nike

*在我将数据添加到我的数据库之前,我添加第一行后,evry thigns 工作正常,我收到此消息 “警告:preg_match() 期望参数 2 为字符串,给定对象”以及存储在我的数据库中的数据....所以当我尝试检索它时,我收到了这条消息“在第 20 行的 etudiant\index.html.twig 中呈现模板期间抛出异常(“警告:preg_match() 期望参数 2 为字符串,给定对象”)。”谁能帮我 ?我不知道我该怎么办 *

EtudiantController.php

<?php

namespace biblioBundle\Controller;

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

use biblioBundle\Entity\Etudiant;
use biblioBundle\Form\EtudiantType;

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

$etudiants = $em->getRepository('biblioBundle:Etudiant')->findAll();

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

/**
* Creates a new Etudiant entity.
*
*/
public function newAction(Request $request)
{
$etudiant = new Etudiant();
$form = $this->createForm(EtudiantType::class, $etudiant);
$form->handleRequest($request);

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

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

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

EtudiantType.php

<?php

namespace biblioBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;


class EtudiantType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('ncin')
->add('carteetudiant')
->add('groupe')
->add('idpersonne',EntityType::class, array(
'class' => 'biblioBundle:Personne',
'choice_label' => function ($category) {
return $category->getIdpersonne();
} ))
;
}

/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'biblioBundle\Entity\Etudiant'
));
}
}

index.html.twig

<table>
<thead>
<tr>
<th>Ncin</th>
<th>Carteetudiant</th>
<th>Groupe</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for etudiant in etudiants %}
<tr>
<td><a href="{{ path('etudiant_show', { 'id': etudiant.idpersonne }) }}">{{ etudiant.ncin }}</a></td>
<td>{{ etudiant.carteetudiant }}</td>
<td>{{ etudiant.groupe }}</td>
<td>
<ul>
<li>
<a href="{{ path('etudiant_show', { 'id': etudiant.idpersonne }) }}">show</a>
</li>
<li>
<a href="{{ path('etudiant_edit', { 'id': etudiant.idpersonne }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>

最佳答案

根据您的表单 EtudiantType,etudiant.idpersonne 是一个 biblioBundle\Entity\Personne 实体。也许你想做的是:

<td><a href="{{ path('etudiant_show', { 'id': etudiant.idpersonne.id }) }}">{{ etudiant.ncin }}</a></td>

就我个人而言,我会将 Etudiant::$idpersonne 重构为 Etudiant::$personne 以反射(reflect)您在其中存储实体而不是整数这一事实。然后我会用 :

<td><a href="{{ path('etudiant_show', { 'id': etudiant.personne.id }) }}">{{ etudiant.ncin }}</a></td>

关于php - 交响乐 : preg_match() expecting parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41039291/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com