尝试从命名空间 AppBundle\Repository 加载 class "Roles"
Attempted to load class "Roles" from namespace AppBundle\Repository
我在数据库中有我的角色:
AppBundle\Entity\Roles:
type: entity
table: Roles
repositoryClass: AppBundle\Repository\Roles
空 class 用于测试目的:
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
use AppBundle\Entity\Roles;
class RolesRepository extends \Doctrine\ORM\EntityRepository
{
}
我的控制器中的简单用例:
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Entity\Roles;
class ClientsController extends CommonController
{
public function newAction(Request $request)
{
// [...]
$role = $this->getDoctrine()
->getRepository('AppBundle:Roles')
->findOneBy(array('role'=>'ROLE_CLIENT'));
// [ ...]
}
}
当我只将 "repositoryClass: \AppBundle\Repository\Roles" 放入 .orm.yml 文件时,出现错误:
Attempted to load class "Roles" from namespace "\AppBundle\Repository".
Did you forget a "use" statement for another namespace?
谁能帮我解决这个问题?
您的存储库 class 名称是 AppBundle\Repository\RolesRepository
,因此在您的实体配置中,而不是:
repositoryClass: AppBundle\Repository\Roles
应该是:
repositoryClass: AppBundle\Repository\RolesRepository
我在数据库中有我的角色:
AppBundle\Entity\Roles:
type: entity
table: Roles
repositoryClass: AppBundle\Repository\Roles
空 class 用于测试目的:
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
use AppBundle\Entity\Roles;
class RolesRepository extends \Doctrine\ORM\EntityRepository
{
}
我的控制器中的简单用例:
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Entity\Roles;
class ClientsController extends CommonController
{
public function newAction(Request $request)
{
// [...]
$role = $this->getDoctrine()
->getRepository('AppBundle:Roles')
->findOneBy(array('role'=>'ROLE_CLIENT'));
// [ ...]
}
}
当我只将 "repositoryClass: \AppBundle\Repository\Roles" 放入 .orm.yml 文件时,出现错误:
Attempted to load class "Roles" from namespace "\AppBundle\Repository". Did you forget a "use" statement for another namespace?
谁能帮我解决这个问题?
您的存储库 class 名称是 AppBundle\Repository\RolesRepository
,因此在您的实体配置中,而不是:
repositoryClass: AppBundle\Repository\Roles
应该是:
repositoryClass: AppBundle\Repository\RolesRepository