I have problems in coding. when I send you the form, and save to the database, a message like this:
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
Here is my code :
$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();
}
}
I wonder with which this issue. The coding of my other, the way this works fine, but I was confused when this method can not be used in this my coding.
From the example you provided, I assume this is line 601
, which is triggering the fatal error:
$students->setFormClass($findclass->getId());
I assume that the method call \ITTBundle\Entity\Student::setFormClass()
requires an object of type \ITTBundle\Entity\FormClass
. You are returning a entity from the database, but then you but then you are explicitly passing the object's id - which is an integer - instead of the FormClass
object itself.
Try this:
$students->setFormClass($findclass);
We can only tell for sure if you show us the method signature of \ITTBundle\Entity\Student::setFormClass()
, but that's my semi-educated assumption. Given the method call itself is throwing an error for an unexpected argument type, I assume the method argument is typed so I guess is that it may look like this:
public function setFormClass(\ITTBundle\Entity\FormClass $formClass)
{
$this->formClass = $formClass;
}
Hope this helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With