php - Silex DoctrineORM: Custom Entity Repository -
i have issue when trying build custom entity repository.
"php message: php fatal error: class 'doctrine\orm\entityrepository' not found in /home/user/projects/app/src/application/database/entityrepository/userrepository.php on line 8
in customrepository.php
file have done this:
<?php namespace application\database\entityrepository; use application\bootstrap bootstrap; use doctrine\orm\entityrepository; class userrepository extends \doctrine\orm\entityrepository { public function getpasswordbyusername($username) { $query = $app['orm.em']->createquery('select u.password application\database\entities\users u (u.username = :username)'); $query->setparameter('username', $username); return $query->getoneornullresult(); } }
and in bootstrap file method loaded through constructor in bootstrap class.
use silex\provider\doctrineserviceprovider silexdocprov; use silex\provider\sessionserviceprovider silexsessprov; use dflydev\silex\provider\doctrineorm\doctrineormserviceprovider docprov; private function initdatabase() { $this->app->register(new silexdocprovj(), array( 'db.options' => array( 'driver' => 'pdo_mysql', 'host' => getenv('dbhost'), 'dbname' => getenv('dbname'), 'user' => getenv('dbuser'), 'password' => getenv('dbpass') ) )); $this->app->register(new docprov(), array( 'orm.em.options' => array( 'mappings' => array( array( 'type' => 'yml', 'namespace' => 'application\database\entities', 'path' => __dir__ . '/../../app/config/mappings' ) ) ) )); }
and mappings file has this:
application\database\entities\users: type: entity table: users repositoryclass: \application\database\entityrepository\userrepository
namespaces case-sensitive.
change
doctrine\orm\entityrepository
to:
doctrine\orm\entityrepository
also there's no need full namespace in
extends \doctrine\orm\entityrepository
because you've imported class
use doctrine\orm\entityrepository;
so can do:
extends entityrepository
Comments
Post a Comment