用户实体:
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!