繁体   English   中英

PHP数组未使用symfony2实体类的构造函数中提供的数据填充

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM