我有一个实体,
// src/Acme/StoreBundle/Entity/Product.php
namespace Acme\StoreBundle\Entity;
class Product
{
protected $name;
protected $price;
protected $description;
}
当我获得产品记录时,我想加入名称和描述。就像是,
// src/Acme/StoreBundle/Entity/Product.php
namespace Acme\StoreBundle\Entity;
class Product
{
protected $name;
protected $price;
protected $description;
protected $heading;
public function __construct()
{
parent::__construct();
$this->heading = $this->name . ' ' . $this->description;
}
}
我尝试在构造函数中设置 preLoad 事件的标题。在它创建之后和序列化之前。似乎没有任何效果。我怎样才能做到这一点?