我尝试编写一个方法,其任务是仅返回与特定实体关联的项目集合的选定元素。
/**
* @ORMOneToMany(targetEntity="PlayerStats", mappedBy="summoner")
* @ORMOrderBy({"player_stat_summary_type" = "ASC"})
*/
protected $player_stats;
public function getPlayerStatsBySummaryType($summary_type)
{
if ($this->player_stats->count() != 0) {
$criteria = Criteria::create()
->where(Criteria::expr()->eq("player_stat_summary_type", $summary_type));
return $this->player_stats->matching($criteria)->first();
}
return null;
}
但是我得到错误:
PHP Fatal error: Cannot access protected property RankingCoreBundleEntityPlayerStats::$player_stat_summary_type in /Users/piotrkowalczuk/Sites/lolranking/vendor/doctrine/common/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php on line 53
知道如何解决这个问题吗?
固定。它应该是:
$criteria = Criteria::create()
->where(Criteria::expr()->eq("playerStatSummaryType", $summary_type));
确保PlyerStats
实体具有getPlayerStatSummaryType()
公共方法。它被@ORMOrderBy
注释和(我想)getPlayerStatsBySummaryType()
内的自定义标准使用。
为类$player_stat_summary_type
属性提供一个 getter RankingCoreBundleEntityPlayerStats
。