symfony 1.4 主义形式绑定
也许是简单的问题,但我只是错过了一些东西。
我有 2 个表,其中有 3 个相同的字段(名称/类型)。
occurrence
和 occurrence_queue
Schema
Occurrence:
tableName: occurrence
columns:
id: {the usual}
date: {type: date}
start_time: {type: time}
end_time: {type: time}
eid: {a forign key}
OccurrenceQueue:
tableName: occurrence_queue
columns:
id: <-Same As Above->
occurrence_id: {the usual}
date: <-Same As Above->
start_time: <-Same As Above->
end_time: <-Same As Above->
然后我有一个基于 Occurrence
构建的模块,即doctrine:generate-module app *name * 发生情况
在这个模块中,我加载了一组发生情况,非常标准,所以这里是 trixy 部分。我想要做的是从 Occurrence
加载 3 个公共字段,但是当我保存表单时,我希望它保存到 OccurrenceQueue
表而不是 Occurrence< /代码>表。
像这样的形式:
DATE: *date picker*
Start Time: HH:MM
End Time: HH:MM
这是我失败的尝试:
public function executeEdit(sfWebRequest $request)
{
$this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
$this->forward404Unless($occurrence = Doctrine_Core::getTable('Occurrence')->find(array($request->getParameter('id'))), sprintf('Object occurrence does not exist (%s).', $request->getParameter('id')));
$request->setParameter('occurrence_id',$occurrence->getId());
$occurrenceQForm = new OccurrenceQueueForm($occurrenceQueue());
$occurrenceQForm->bind($request->getParameter($occurrenceQForm->getName(),$request->getFiles($occurrenceQForm->getName()));
if($occurrenceQForm->isValid())
{
$occurrenceQForm->save();
$this->redirect("happyness");
}
}
这永远不会验证。我假设因为字段和验证是相同的,所以都是黄金,但事实并非如此。那么问题来了,我该如何完成这个任务呢?最后的想法是 OccurrenceQueue
表将用于更新 Occurrence
表。
马哈洛的帮助!
Perhaps simple question and I am just missing something.
I have 2 tables that have 3 of the same fields(names/types).
occurrence
and occurrence_queue
Schema
Occurrence:
tableName: occurrence
columns:
id: {the usual}
date: {type: date}
start_time: {type: time}
end_time: {type: time}
eid: {a forign key}
OccurrenceQueue:
tableName: occurrence_queue
columns:
id: <-Same As Above->
occurrence_id: {the usual}
date: <-Same As Above->
start_time: <-Same As Above->
end_time: <-Same As Above->
I then have a module That is built off Occurrence
i.e. doctrine:generate-module app *name* Occurrence
In this module I load a set of Occurrences, pretty standard so here comes the trixy part. What I want to do is load the 3 common field from Occurrence
but when I save the form I want it to save to the OccurrenceQueue
table instead of the Occurrence
table.
Form like this:
DATE: *date picker*
Start Time: HH:MM
End Time: HH:MM
Here is my failed attempt at this:
public function executeEdit(sfWebRequest $request)
{
$this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
$this->forward404Unless($occurrence = Doctrine_Core::getTable('Occurrence')->find(array($request->getParameter('id'))), sprintf('Object occurrence does not exist (%s).', $request->getParameter('id')));
$request->setParameter('occurrence_id',$occurrence->getId());
$occurrenceQForm = new OccurrenceQueueForm($occurrenceQueue());
$occurrenceQForm->bind($request->getParameter($occurrenceQForm->getName(),$request->getFiles($occurrenceQForm->getName()));
if($occurrenceQForm->isValid())
{
$occurrenceQForm->save();
$this->redirect("happyness");
}
}
This never validates. I assumed because the field and the validations were the same it would be all golden and what not, well not the case. So the question is, how do I accomplish this task? In the end The idea is the OccurrenceQueue
table will be used to update the Occurrence
table.
Mahalo for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是表单永远不会绑定ocurrence_id。当使用 sfForm 时,它使用 nameFormat ( $form->getName() 部分)来生成该字段的名称,因此为了让您工作,请像这样尝试:
这不是最好的这样做的方法,但它会起作用。我真正要做的是将 Ocurrence 按参数传递给 OcurrenceQForm,如下所示:
在您的 OccurrenceForm 中:
The problem is that the form is never binding the ocurrence_id. When using a sfForm it uses the nameFormat (the $form->getName() part) to generate the name of that field, so for you to work try it like this:
This is not the best way to do it but it will work. What would i really do is by passing the Ocurrence by parameter to the OcurrenceQForm like this:
And in your OccurrenceForm: