1

我怎样才能做到这一点?

我正在努力:

$this->form->getObject()->setWebsiteid($website);

$this->form->setDefault('websiteid', $website);

$request->setParameter('websiteid', $website);

上面的任何一个都不起作用

我的代码:

$this->form = new sfGuardRegisterForm();

if ($request->isMethod('post'))
{
  $website=new Website();
  $website->save();

  $this->form->bind($request->getParameter($this->form->getName()));
  if ($this->form->isValid())
  {
    /* here I try do that */
    $this->form->getObject()->setWebsiteid($website);
    /* here I try do that end */

    $user = $this->form->save();
    $this->getUser()->signIn($user);

    $this->redirect('@homepage');
  }
}
4

1 回答 1

1

websiteidUser模型的一部分吗?

websiteid在表单中使用 的小部件吗?

您可以在保存后添加值:

$user = $this->form->save();
$user->setWebsiteid($website);
$user->save();

但第一个解决方案对我来说似乎没问题..

于 2012-04-18T12:43:55.680 回答