开发者

Two forms in one module

开发者 https://www.devze.com 2023-03-31 05:01 出处:网络
I would like to modify two forms in one page. I generated a module with Doctrine. I have: public function executeEdit(sfWebRequest $request)

I would like to modify two forms in one page. I generated a module with Doctrine. I have:

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.

I added:

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

and I get this error:

 500 | Internal Server Error | sfException The "OtherForm" form only
 accepts a "Other" object.

I use findByNewsId()

This works ok - if I make foreach then I have these objects, but I can't show this开发者_如何学JAVA in the Form. How can I achieve this?


It sounds (roughly) like you're looking to edit multiple objects within a single form - so in your example, multiple "Other" items (your question is currently slightly unclear). If so, you'll probably want to take a look at Symfony's embedded forms functionality - see this tutorial for details.

0

精彩评论

暂无评论...
验证码 换一张
取 消