次のエンティティ/クラスがあります:
class Product
{
/**
* @Groups({"marketplace"})
* @Accessor(getter="getShopRef")
* @ORM\ManyToOne(targetEntity="App\MainBundle\Entity\Shop", inversedBy="products")
* @ORM\JoinColumn(name="shop_id", referencedColumnName="id", onDelete="CASCADE" , nullable=false)
*/
protected $shop;
/**
* Set shop
*
* @param Shopious\MainBundle\Entity\Shop $shop
* @return Product
*/
public function setShop(\Shopious\MainBundle\Entity\Shop $shop)
{
$this->shop = $shop;
return $this;
}
/*
* reference of shop
*/
public function getShopRef()
{
return array(
"id"=>$this->shop->getId(),
"name" => $this->shop->getName(),
"description" => $this->shop->getDescription(),
"shoplogo" => $this->shop->getShoplogo(),
"ref"=>"/shop/".$this->shop->getId(),
"is_locked" => $this->shop->getIsLocked(),
"like_count" => $this->shop->getOwner()->getLikeCount(),
"followers_count" => count($this->shop->getOwner()->getFollowers()),
"following_count" => count($this->shop->getOwner()->getFollowing()),
);
}
}
基本的に、上記のコードが言っていることは、ショップを要求するときにこのカスタム ゲッターを使用することです。
というProduct
オブジェクトが$product
あり、" " という名前の shopref 配列/辞書に新しいキーを追加したいとしrecent_items
ます。どうすればいいですか?これまでのところ、私はこれをやろうとしてきました:
$product->getShopRef()["recent_items"] = $userRecentItem;
しかし、これは機能しません。ショップ参照には何も設定されていません。そうすることで、'recent_items' が shop_ref に設定されることを期待しています。