1ページで2つのフォームを修正したいです。 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);
}
これはうまくいきます。
追加した:
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をするなら、私はこれらのオブジェクトを持っています、しかし私はフォームでこれを示すことができません。 どうすればこれを達成できますか?
回答:
回答№1は1(おおまかに言って)あなたが編集しようとしているようですね一つのフォーム内に複数のオブジェクト - あなたの例では、複数の "その他"の項目(あなたの質問は現在わずかに不明瞭です)。もしそうなら、あなたはおそらく "Symfony"の埋め込みフォーム機能を見たいと思うでしょう。 このチュートリアル 詳細については。