Symfony2可捕获致命错误:参数1传递给。。。必须是…的一个实例。。。给定的整数,在中调用
我在编码方面有问题。当我向您发送表单并保存到数据库时,会出现如下消息:Symfony2可捕获致命错误:参数1传递给。。。必须是…的一个实例。。。给定的整数,在中调用,symfony,set,Symfony,Set,我在编码方面有问题。当我向您发送表单并保存到数据库时,会出现如下消息: 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\s
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行,它触发了致命错误:
$students->setFormClass($findclass->getId());
我假设方法调用\ITTBundle\Entity\Student::setFormClass()
需要类型为\ITTBundle\Entity\FormClass
的对象。您正在从数据库返回一个实体,但随后您显式地传递了对象的id(它是一个整数),而不是FormClass
对象本身
试试这个:
$students->setFormClass($findclass);
如果您向我们展示\ITTBundle\Entity\Student::setFormClass()
的方法签名,我们只能确定,但这是我半教育的假设。鉴于方法调用本身为意外参数类型抛出错误,我假设方法参数是类型化的,因此我猜它可能如下所示:
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
公共函数setFormClass(\ITTBundle\Entity\FormClass$FormClass)
{
$this->formClass=$formClass;
}
希望这有帮助:)没问题:)很乐意帮忙。不知道是谁否决了你,似乎有点不合理,因为你的问题对我来说很好。很好!我理解你的问题。