[英]PHP array is not populated with data provided in constructor of symfony2 entity class
在我的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'] = "";
}
但是,上面的代碼似乎沒有填充類變量。
在$this->avaliabletags
上使用print_r
導致array()
我究竟做錯了什么?
看來問題與未調用構造函數有關。
根據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"
));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.