我想在一个页面中修改两个表单。我用Doctrine生成了一个模块。我:
public function executeEdit(sfWebRequest $request)
{
$this->forward404Unless($news = Doctrine_Core::getTable('News')->find(array($request->getParameter('news_id'))), sprintf('Object news does not exist (%s).', $request->getParameter('news_id')));
$this->form = new NewsForm($news);
}
this works fine.
我补充说:
public function executeEdit(sfWebRequest $request)
{
$this->forward404Unless($news = Doctrine_Core::getTable('News')->find(array($request->getParameter('news_id'))), sprintf('Object news does not exist (%s).', $request->getParameter('news_id')));
$this->form = new NewsForm($news);
$this->forward404Unless($other = Doctrine_Core::getTable('Other')->findByNewsId(array($request->getParameter('other_id'))), sprintf('Object other does not exist (%s).', $request->getParameter('other_id')));
$this->form = new OtherForm($other);
}
,我得到这个错误:
500 | Internal Server Error | sfException The "OtherForm" form only
accepts a "Other" object.
我使用findByNewsId()
这工作正常-如果我使foreach,然后我有这些对象,但我不能在表单中显示它。我怎样才能做到这一点呢?
听起来(大致)像您希望在单个表单中编辑多个对象-所以在您的示例中,多个"其他"项(您的问题目前有点不清楚)。如果是这样,你可能会想看看Symfony的嵌入式表单功能——详细信息请参见本教程。