gpt4 book ai didi

Symfony2 可捕获的 fatal error : Argument 1 passed to . .. 必须是给定的...整数的实例,在

转载 作者:行者123 更新时间:2023-12-02 10:17:51 24 4
gpt4 key购买 nike

我在编码时遇到问题。当我向您发送表单并将其保存到数据库时,会显示如下消息:

Catchable fatal error: Argument 1 passed to ITTBundle\Entity\Student::setFormClass() must be an instance of ITTBundle\Entity\FormClass, integer given, called in C:\Users\Rivan\Documents\DigitalSchoolBase\Symfony2\src\ITTBundle\Controller\ConfigureController.php on line 601 and defined in C:\Users\Rivan\Documents\DigitalSchoolBase\Symfony2\src\ITTBundle\Entity\Student.php on line 901

这是我的代码:

  $findclass = $this->getDoctrine()
->getRepository('ITTBundle:FormClass')
->findOneBy(array('class_level' => $classlevel->getId(), 'letter' => $letter, 'class_major' => $classmajor->getId()));

//print_r($findclass->getId()); exit;
if( empty($error_message) )
{
If ($findclass)
{
$em = $this->getDoctrine()->getManager();
$students->setFormClass($findclass->getId());
$em->persist($students);
$em->flush();
}

}

我想知道这个问题与哪个有关。我的其他编码,这种工作方式很好,但是当这个方法不能在我的编码中使用时,我感到很困惑。

最佳答案

从您提供的示例中,我假设这是行601,它触发了 fatal error :

$students->setFormClass($findclass->getId());

我假设方法调用 \ITTBundle\Entity\Student::setFormClass() 需要一个 \ITTBundle\Entity\FormClass 类型的对象。您正在从数据库返回一个实体,但是随后您显式传递了对象的 id(这是一个整数),而不是 FormClass 对象本身。

试试这个:

$students->setFormClass($findclass);

只有您向我们展示 \ITTBundle\Entity\Student::setFormClass() 的方法签名,我们才能确定,但​​这是我的半受过教育的假设。鉴于方法调用本身会抛出意外参数类型的错误,我假设方法参数已输入,所以我猜它可能如下所示:

public function setFormClass(\ITTBundle\Entity\FormClass $formClass)
{
$this->formClass = $formClass;
}

希望这有帮助:)

关于Symfony2 可捕获的 fatal error : Argument 1 passed to . .. 必须是给定的...整数的实例,在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31378127/

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