1

I try to write a method whose task would be to return only selected elements of the collection of items associated with a particular entity.

/**
 * @ORM\OneToMany(targetEntity="PlayerStats", mappedBy="summoner")
 * @ORM\OrderBy({"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;
}

but i get error:

PHP Fatal error:  Cannot access protected property Ranking\CoreBundle\Entity\PlayerStats::$player_stat_summary_type in /Users/piotrkowalczuk/Sites/lolranking/vendor/doctrine/common/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php on line 53

any idea how to fix this?

4

3 回答 3

2

固定的。它应该是:

    $criteria = Criteria::create()
        ->where(Criteria::expr()->eq("playerStatSummaryType", $summary_type));
于 2012-11-18T15:12:29.917 回答
1

确保PlyerStats实体具有getPlayerStatSummaryType()公共方法。注释正在使用它,@ORM\OrderBy并且(我想)你的自定义标准正在使用它getPlayerStatsBySummaryType()

于 2012-11-18T11:13:43.493 回答
0

$player_stat_summary_type为类中的属性提供一个 getter Ranking\CoreBundle\Entity\PlayerStats

于 2012-11-18T11:16:37.917 回答