Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass a variable to a Symfony Form

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

The main problem I have is that in the drop down list I only want to show the courses in which the student is currently not enrolled.

I already have a function in the model (in Student.class.php) which returns all the courses in which the student is not enrolled but the problem is I don't know how to pass the student to the configure() of the form. I have tried several options like passing it with the constructor of the form to a global variable or a special set method but none of them have worked.

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

Thanks!

like image 341
Juan Besa Avatar asked May 18 '10 00:05

Juan Besa


1 Answers

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');
like image 79
Tom Avatar answered Nov 01 '22 06:11

Tom