SYMFONY:在链条配置的名称空间Userbundle Entity,fos userBundle mod



我尝试按照本教程进行分页:https://knpuniversity.com/screencast/symfony-rest3/pagerfanta-pagination

目前我已经安装了white-october/pagerfanta-bundle,当我将用户存储库做以下时:

<?php
// src/UsersBundle/Repository/UserRepository.php
namespace UsersBundleRepository;

use DoctrineORMEntityRepository;
class UserRepository extends EntityRepository {
    public function findAllQueryBuilder() {
        return $this->createQueryBuilder('user');
    }
}

在我的控制器动作中,我做到了:

<?php
// src/UsersBundle/Controller/UsersController.php
namespace UsersBundleController;
// use statements ...
/**
 * Class UsersController
 *
 * @package UsersBundleController
 *
 * @RestRouteResource("user", pluralize=false)
 * @RestNamePrefix( "api_v1_" )
 */
class UsersController extends FOSRestController implements ClassResourceInterface {
    // ...
    /**
     * Responsible to list all the registered users.
     *
     * @RestQueryParam(name="page", default="1", requirements="d+",nullable=true)
     *
     * @return array|Traversable
     */
    public function getListAction( ParamFetcher $param_fetcher ) {
        if ( ! $this->isGranted( 'ROLE_ADMIN' ) ) {
            throw new UnauthorizedHttpException( 'You do not have sufficient permission to access this resource' );
        }
        $qb = $this->getDoctrine()
            ->getRepository('UsersBundleRepositoryUserRepository')
            ->findAllQueryBuilder();
        $adapter = new DoctrineORMAdapter( $qb );
        $users = $this->user_manager->findUsers();
        return $users;
    }
    // ...
}

我得到了此输出:

{"code":500,"message":"The class 'UsersBundle\Repository\UserRepository' was not found in the chain configured namespaces UsersBundle\Entity, FOS\UserBundle\Model"}

有人知道输出意味着什么?不幸的是,我是Symfony的新手,我不明白此输出的问题是什么。

$qb = $this->getDoctrine()
        ->getRepository('UsersBundleRepositoryUserRepository')
        ->findAllQueryBuilder();

您应该通过您的实体找到您的存储库,所以类似这样的东西

$qb = $this->getDoctrine()
        ->getRepository('User:class')
        ->findAllQueryBuilder();

doc:https://symfony.com/doc/current/doctrine.html#fetching-objects-from-the-database

,在您的User实体中,您应该有类似的东西

/**
 * @ORMTable(name="User")
 * @ORMEntity(repositoryClass=UserRepository::class)
 */
class User {
...

相关内容

  • 没有找到相关文章

最新更新