Symfony 2 不在编辑和创建表单中显示字段

Symfony 2 doesn't display field in edit and create forms

我有实体 good,其中包含以下字段:名称、成本、描述等。如果我想创建新商品或编辑,我不会有字段 name 结果 html。那是在 good entity:

/**
 * @var string
 */
private $name;
/**
 * Set name
 *
 * @param string $name
 * @return Good
 */
public function setName($name)
{
    $this->name = $name;

    return $this;
}

/**
 * Get name
 *
 * @return string
 */
public function getName()
{
    return $this->name;
}

好控制器:

 public function editAction(Request $request, Good $good)
    {
       ...
        $editForm = $this->createForm('Shop\ShopBundle\Form\GoodType', $good);
       ...
  }

创建操作有示例形式。如果我尝试在树枝模板中调用这样的代码,

{{ form_label(edit_form.name) }}

我要

Neither the property "name" nor one of the methods "name()", "getname()"/"isname()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView".

怎么了?

您缺少表单类型的说明 每个实体都应该有一个文件 EntityFormType.php 在那里你将像这样添加你的字段

    $builder->add('name', null, array(
    'required'   => false,
    'empty_data' => 'John Doe',
    ));