0

我正在使用 symfony 1,问题是当我使用 RenderPartial 函数将小部件放入弹出窗口时,出现以下错误:

注意:未定义变量:第 49 行 ...templates/template.php 中的表单
致命​​错误:第 49 行 .../templates/template.php 中的非对象调用成员函数 open()

这是我在 class.php 中的函数:

public function executeProduct(sfWebRequest $request)
{
  $this->renderPartial('integrate/Product');
  $form = new ProductForm();

  if ($request->isMethod('post') && $request->hasParameter($form->getName()))
  {
    $form->bindRequest($request); 
    if ($form->isValid())
    {
      $form->save();
      return $this->redirectBack();
    }
    $this->forms['product'] = $form;
  }
  else 
  {
    foreach ($form->getGlobalErrors() as $nom=>$error)
    {
      echo $nom.':'.$error;
    }
  }
}

我能做些什么来解决这个问题?

4

2 回答 2

0

渲染部分时,您必须手动提供变量。尝试

$this->renderPartial('integrate/Product', array('form' => $form));

并在动作结束时移动呼叫。

于 2012-11-22T16:32:47.453 回答
0

不,不幸的是这种方法是错误的,我必须把if ($request->isMethod('post'))

我修改了我的模板:

<form action="<?php echo url_for('integrate/Product') ?>" method="POST">            
<ul>
<ul> <li> <?php echo $form['name']->label()?> </li>
<?php echo $form['name']->field()?>

 </ul> 

中的所有块:

if ($request->isMethod('post') && $request->hasParameter($form->getName()))

如果我删除它,它可以工作,但我必须把它,所以在这个改变之后;我有这个错误:

注意:未定义变量:第 49 行 ...templates/template.php 中的表单 致命​​错误:第 49 行 .../templates/template.php 中的非对象调用成员函数 label()

于 2012-11-21T15:20:28.390 回答