将变量传递给 Symfony 表单

发布于 2024-09-01 17:45:39 字数 311 浏览 2 评论 0原文

我正在使用 Symfony 1.4 和 Doctrine 为一所学校构建一个 Web 应用程序,我想制作一个非常简单的表单来向学生添加课程。

我遇到的主要问题是,在下拉列表中我只想显示学生当前未注册的课程。

我已经在模型中(在 Student.class.php 中)有一个函数,它返回学生未注册的所有课程,但问题是我不知道如何将学生传递给表单的 configure() 。我尝试了多种选项,例如将其与表单的构造函数一起传递给全局变量或特殊的 set 方法,但它们都不起作用。

是否有任何形式可以将学生传递给configure()方法?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

箜明 2024-09-08 17:45:39

这应该对你有用......

In your action:

$this->form = new StudentCourseForm(array(), array('student_id' => $student_id));

In the form class:

$this->getOption('student_id');

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');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文