Reputation: 414
I have a User
Entity class and I craete a UserRepository.php
in the same directory to put my custom methods in it, But when I use that in a contoller using this syntax it won't work:
my Repository:
namespace Doobin\UserBundle\Entity;
use Doctrine\ORM\EntityRepository;
class UserRepository extends EntityRepository
{
public function pageAccess($User=1,$Page='_home')
{
$stmt="Somthing to test";
return $stmt;
}
}
My controller to use repository:
use Doobin\UserBundle\Entity\User;
.
.
.
.
$em = $this->getDoctrine()->getManager();
$products = $em->getRepository('UserBundle:User')->pageAccess();
var_dump($products);
When I use it, It counld't find the pageAccess method.
Should I introduce the repository somewhere? becuase the tuturial itself didn't say anything.
Upvotes: 0
Views: 74
Reputation: 782
In your User entity you should add annotation on the top of the class :
/**
* User.
*
* @ORM\Table(name="my_user")
* @ORM\Entity(repositoryClass="UserRepository")
*/
class User
{
}
Upvotes: 1