Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
115 views
in Technique[技术] by (71.8m points)

symfony1 - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...