私自身のエンティティのリポジトリをオーバーライドしようとすると少し不満があります。Sylius - カスタムEntityRepositoryを実装する方法
私のエンティティのリストを特別な方法で取得するには、カスタムリポジトリメソッドを作成する必要があります。 1つのqueryBuilderはHaving
とOrderBy
です。
質問私の設定をSyliusと言うにはどうしたらいいですか?デフォルトではなくカスタムレポジトリを利用します。
私はこれを試してみてください。
sylius_resource:
resources:
dinamic.category:
classes:
model: App\Bundle\SyliusBlogBundle\Entity\PostCategory
repository: App\Bundle\SyliusBlogBundle\Repository\PostCategoryRepository
これは私のリポジトリである:私は、このメソッドを使用しようとすると
<?php
namespace App\Bundle\SyliusBlogBundle\Repository;
use Doctrine\ORM\EntityRepository;
class PostCategoryRepository extends EntityRepository
{
public function findCategoriesMenu()
{
$queryBuilder = $this->createQueryBuilder('c');
return $queryBuilder
->addSelect('COUNT(p.id) as totalPosts')
->leftJoin('c.posts', 'p')
->andWhere('p.published = true')
->having('totalPosts > 0')
->addGroupBy('p.id')
;
}
}
、symfonyは私に、このエラーがスローされます。
An exception has been thrown during the rendering of a template ("Undefined method 'findCategoriesMenu'. The method name must start with either findBy or findOneBy!")
あなたは正しいですSteffen!それは動作します、ありがとうございます。 –