在我的php类(symfony2实体类(中,我有可用的类变量:
protected $avaliabletags = array();
在构造函数中,我将数据放入该数组:
/**
* Constructor
*/
public function __construct()
{
$this->avaliabletags['zatwierdzony']['name'] = "Zatwierdzony";
$this->avaliabletags['zatwierdzony']['role'] = "ROLE_ACCEPTTAG";
$this->avaliabletags['zatwierdzony']['label'] = "";
$this->avaliabletags['finalized']['name'] = "Finalized";
$this->avaliabletags['finalized']['role'] = "ROLE_ACCEPTDOC";
$this->avaliabletags['finalized']['label'] = "";
}
然而,上面的代码似乎并没有填充类变量。
在array()
的$this->avaliabletags
结果上使用print_r
我做错了什么?
问题似乎与未调用构造函数有关。
根据doctrine2文档,doctrine2从不调用实体的__construct((方法。http://www.doctrine-project.org/docs/orm/2.0/en/reference/architecture.html?highlight=construct.
因此,我将代码更改为:
/**
* Baza dostepnych tagów
*/
protected $avaliabletags = array(
"zatwierdzony" => array(
"name" => "Zatwierdzony",
"role" => "ROLE_ACCEPTTAG"
),
"finalized" => array(
"name" => "Finalized",
"role" => "ROLE_ACCEPTDOC"
));