我有以下实体/类:
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;
但这不起作用。商店参考上没有设置任何内容。我希望通过这样做,将在 shop_ref 上设置“recent_items”。