我有一个全新的 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);
}
}