Php 未找到FosBundle路由

Php 未找到FosBundle路由,php,rest,symfony,fosrestbundle,Php,Rest,Symfony,Fosrestbundle,目前正在学习Symfony 3.x上的教程 我的问题是我一直使用使用此代码的getAction()方法 namespace SwipeBundle\Controller\Backend\API; use FOS\RestBundle\Controller\Annotations as Rest; use FOS\RestBundle\Controller\FOSRestController; use Symfony\Component\HttpFoundation\Response; use

目前正在学习Symfony 3.x上的教程

我的问题是我一直使用使用此代码的
getAction()
方法

namespace SwipeBundle\Controller\Backend\API;

use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\Response;
use FOS\RestBundle\View\View;

class UserController extends FOSRestController
{
    /**
     * @Rest\Get("/api/user")
     */
    public function getAction() {
        $restresult = $this->getDoctrine()
            ->getRepository('SwipeBundle:User')
            ->findAll();

        if ($restresult) {
            return new View("there are no users exist", Response::HTTP_NOT_FOUND);
        }
        return $restresult;
    }
}
检查日志上的错误:

未捕获的PHP异常 Symfony\Component\HttpKernel\Exception\NotFoundHttpException:“否 在找到“GET/api/user”的路由 /home/swipecom/contactless/var/cache/prod/classes.php行4595 {“异常”:“[对象] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(代码: 0):在上找不到“GET/api/user”的路由 /home/swipecom/contactless/var/cache/prod/classes.php:4595, Symfony\Component\Routing\Exception\ResourceNotFoundException(代码: 0):在 /home/swipecom/contactless/var/cache/prod/appProdProjectContainerUrlMatcher.php:750)} []

我检查并配置了
FOSRest配置和Nelmio
,但仍然不工作

这是:

# Nelmio CORS Configuration
nelmio_cors:
    defaults:
        allow_credentials: false
        allow_origin: ['*']
        allow_headers: ['*']
        allow_methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']
        max_age: 3600
        hosts: []
        origin_regex: false

# FOSRest Configuration
fos_rest:
    body_listener: true
    format_listener:
        rules:
            - { path: '^/', priorities: ['text/html'], fallback_format: html, prefer_extension: false }
            - { path: '^/api/', priorities: ['json'], fallback_format: json, prefer_extension: false }
    param_fetcher_listener: true
    view:
        view_response_listener: 'force'
        formats:
            json: true
            xml: true
            yml: true

使用路径属性作为示例:

 * @Rest\Get(path="/api/user")
而不是

 * @Rest\Get("/api/user")
您可以使用console命令进行调试:

显示所有可用路线:

控制台调试:路由器

要查看谁符合您的路线:

控制台路由器:匹配/api/用户

注意:

如果问题仍然存在,请使用命令进行检查

控制台调试:路由器--显示控制器

寻找你的控制器,看看会发生什么。例如,如果您的控制器未列出,请按照文档中的说明检查路由配置


希望有此帮助

我刚刚在路线中添加了路径属性。path=“/api/user”仍然不工作,我也使用路由器检查了路由器:匹配,错误是没有一条路由与path@phpmeter请参阅我的更新:尝试使用
控制台调试:路由器--显示控制器
并搜索控制器找不到我创建的userController:(我如何解决这个问题?@phpmeter检查官方文档(可能教程遗漏了一些细节),例如,如果您在
routing.yml
文件中添加bundle的配置,如所述更新:我现在可以看到控制器,但我还没有得到路由