3

用户实体:

namespace Core\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * User
 * @ORM\Entity(repositoryClass="Core\UserBundle\Entity\UserRepository")
 * @ORM\Table(name="user")
 */
class User
{
}

用户存储库:

<?php 
# src/Core/UserBundle/Entity/UserRepository.php

namespace Core\UserBundle\Entity;
use Doctrine\ORM\EntityRepository;

class UserRepository extends EntityRepository
{

    public function example()
    {
        return "hello word";
    }
}

控制器 :

$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('CoreUserBundle:User');
$repo->example();

笔记 :get_class($repo) => Doctrine\ORM\EntityRepository

错误:

Error Message : Undefined method 'example'. The method name must start with either findBy or findOneBy!
4

1 回答 1

0

试试这个

$repo = $em->getRepository('UserBundle:User');

于 2013-10-21T21:31:25.867 回答