2013-10-04 25 views
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; 
    } 
} 

我試過設置上的預載荷事件的標題,在構造函數中。在創建之後和序列化之前。似乎沒有任何工作。我怎樣才能做到這一點?

回答

1

你可以嘗試只用吸附劑:

public function getHeading() 
{ 
    return $this->name . ' ' . $this->description; 
} 
+0

也試過這樣。看起來它實際上是JMS序列化程序刪除屬性的問題。 – shapeshifter