PHP数组未填充symfony2实体类构造函数中提供的数据
在我的php类(symfony2实体类)中,我有一个可用的类变量:PHP数组未填充symfony2实体类构造函数中提供的数据,php,arrays,symfony,Php,Arrays,Symfony,在我的php类(symfony2实体类)中,我有一个可用的类变量: protected $avaliabletags = array(); 而不是在构造函数中,我将数据放入该数组: /** * Constructor */ public function __construct() { $this->avaliabletags['zatwierdzony']['name'] = "Zatwierdzony"; $this
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'] = "";
}
然而,上面的代码似乎并没有填充类变量
在$this->availabletags
上使用print\r
可生成array()
我做错了什么?问题似乎与未调用构造函数有关 根据doctrine2文档,doctrine2从不调用实体的_construct()方法 因此,我将代码更改为:
/**
* Baza dostepnych tagów
*/
protected $avaliabletags = array(
"zatwierdzony" => array(
"name" => "Zatwierdzony",
"role" => "ROLE_ACCEPTTAG"
),
"finalized" => array(
"name" => "Finalized",
"role" => "ROLE_ACCEPTDOC"
));
您在哪里调用
print\r
?你确定在constructor
和调用print\r
之间没有清除数组吗?我已经搜索了类文件,没有找到对$availabletags的其他引用。尽管如此,我还是怀疑_construct()是否会像puting there die()那样执行;不会导致空白页。显示测试数组值的代码