我有以下实体/类:
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
的{{1}}对象,我想在shopref数组/字典中添加一个名为“$product
”的新密钥。我该怎么办?到目前为止,我一直在尝试这样做:
recent_items
但这不起作用。商店参考没有设置任何东西。我希望通过这样做可以在shop_ref上设置'recent_items'。