【发布时间】:2021-07-04 11:15:54
【问题描述】:
我在实体类中创建了小方法,我可以在其中更改两个字段中的一些内容:
这是我的水果实体方法:
/**+
* @return $this
*/
public function freeBasket(): Fruit
{
$this->setFreshBasketName($this->getBasketName());
$this->seBasketName(null);
return $this;
}
但我有一个想法,因为这是在 Fruit 类中,所以不需要为它使用方法,有一种方法可以直接访问类属性,而不是删除 setFreshBasketName() 方法。
我怎样才能做到这一点? Symfony 的新功能。 :)
【问题讨论】:
-
与 Symfony 或 Doctrine 无关。这是基本的 PHP 知识和property access。
标签: php