我有两个类。一个类事件和一个Suite
在事件的形式中,我想从表套件的内容中选择构建。例如在套房(桌子)我有多有少。我希望在我的选择中看到'more'和'less'。
我尝试使用一个实体字段,但它不工作,我总是得到消息
"既不是属性"suite"也不是方法"getSuite()"....
现在我在事件类中有一个关系OneToOne我的formtype是这样的
->add('Suite', 'entity', array('class'=> 'Suite','choice_label'=>'suite'));
您的class
选项看起来很可疑-除非它与您的formtype类位于相同的名称空间中,否则它需要看起来像这样:
->add('Suite','entity',array('class'=>'AppBundle:Suite','choice_label'=>'suite'));
现在,假设这不是错误的原因(听起来好像不是-这意味着你已经创建了一个杆子你的背通过不遵循约定),那么错误包含了你需要知道的一切:你已经忽略了创建一个getter为您的套件实体的suite
属性。可以是像这样简单的:
/**
* @ORM'Entity
* @ORM'Table(name="suite")
*/
class Suite
{
....
/**
* @ORM'Column( type="string", length=32 )
*/
protected $suite;
....
public function getSuite()
{
return $this->suite;
}
这甚至可以自动完成(如果你遵循既定的惯例):
生成getter和setter
以下是一些文档:
数据库和理论和实体字段类型