0

我有一个实体,

// 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 事件的标题。在它创建之后和序列化之前。似乎没有任何效果。我怎样才能做到这一点?

4

1 回答 1

1

您可以尝试仅使用 getter:

public function getHeading()
{
    return $this->name . ' ' . $this->description;
}
于 2013-10-04T07:45:22.797 回答