doctrine2 - How to access a custom repository from a controller in doctrine 2.0 and Zend framework? -
im unable access custom repository controller in doctrine 2.0 , zend framework?
i have file structure following:-
application/controllers /configs /domain/ entities/user.php /mappings/user.php proxies/ repositories/ vendor/ doctrine
in user.php, have included this:
namespace repositories; use doctrine\orm\entityrepository; /** * @entity(repositoryclass="repositories\userrepository") * @table(name="user") */ class user { }
even tried
namespace entities; use doctrine\orm\entityrepository; /** * @entity(repositoryclass="entities\userrepository") * @table(name="user") */ class user { }
ive generated repositories domain/repositories command.
now have customized repositories in folder domain/repositories. ill want access ex: userrepository in usercontroller.php tried this.
$this->em = zend_registry::get('em'); $userlist = $this->em->getrepository('repostories\user')->getusers();
output: no such file or directory
if tried:
$this->em->getrepository('entities\user')->getusers();
output: getusers() function missing. ur function should start findby
please in regards this.
thanks, hephzibah.
start repository
// repositories/userrepository.php namespace repositories; use doctrine\orm\entityrepository; class userrepository extends entityrepository { public function getusers() { // etc } }
now entity
// entities/user.php namespace entities; /** * @entity(repositoryclass="repositories\userrepository") */ class user { // etc }
provided autoloader can find classes in both repositories
, entities
namespaces, following should work
$em->getrepository('entities\user')->getusers();
Comments
Post a Comment