Passing a variable to a Symfony form

I am building a web application using Symfony 1.4 and Doctrine for school and I want to make a very simple form to add a course to the student.

The main problem I am facing is that in the drop-down list I want to show only those courses in which the student is not currently registered.

I already have a function in the model (in Student.class.php) that returns all courses in which the student is not registered, but the problem is that I don’t know how to pass the student to configure () forms. I tried several options, for example, passing it with the form constructor to a global variable or a special sets method, but none of them worked.

Is there any form for passing the configure () method to the student?

Thanks!

+4
source share
1 answer

This should work for you ...

In your action: $this->form = new StudentCourseForm(array(), array('student_id' => $student_id)); In the form class: $this->getOption('student_id'); 
+17
source

Source: https://habr.com/ru/post/1310061/


All Articles