0

我有一个全新的 Symfony2 应用程序,并且我 100% 确定我已经完全按照http://symfony.com/doc/current/book/doctrine.html#custom-repository-classes进行操作。但是我收到以下错误;

Entity 'Core\MainBundle\Entity\LandingPromotions' has no field 'promotionType'. You can therefore not call 'findByPromotionType' on the entities' repository

我不知道我错过了什么。代码如下;

登陆促销

<?php
namespace Core\MainBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Core\MainBundle\Entity\LandingPromotions
*
* @ORM\Entity(repositoryClass="Core\MainBundle\Entity\PromotionRepository")
* @ORM\Table(name="landing_promotions")
*/
class LandingPromotions
{
//Normal entity stuff
}

PromotionRepository.php

namespace Core\MainBundle\Entity;

use Doctrine\ORM\EntityRepository;

class PromotionRepository extends EntityRepository
{
public function findByPromotionType($typeId)
{
}
}

控制器

namespace Core\MainBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Core\MainBundle\Entity\Game;
use Core\MainBundle\Entity\LandingPromotions as LandingPromotions;

class GameController extends Controller
{
/**
* @Route("{_locale}/games/")
* @Template()
*/
public function indexAction($_locale)
{
$lp_repo = $this->getDoctrine()->getRepository('CoreMainBundle:LandingPromotions');

$lp_repo->findByPromotionType(2);
}
}
4

1 回答 1

1

经过一番拉扯和诅咒后,我发现实体没有使用 PHP 注释,而是使用 XML 版本。我不知道这是怎么混在一起的,但这将是明天的问题。

于 2013-01-03T22:04:25.943 回答