【问题标题】:Symfony3 404 NotFoundHttpExceptionSymfony3 404 NotFoundHttpException
【发布时间】:2016-08-10 12:57:47
【问题描述】:

我正在使用 Symfony3 进行开发,现在我的问题是尝试访问“http://localhost:8000/auth page”时出现“404 错误”

dev.log

[2016-04-18 18:30:14] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "GuideBundle\Entity\MedicalStaff object not found." at D:\Elya\КПИ\6 семестр\TSPP\mg\vendor\sensio\framework-extra-bundle\Request\ParamConverter\DoctrineParamConverter.php line 66  []

它以前有效(我不记得我做了什么导致它失败)。 我的 routing.yml

auth:
    path: /auth
    defaults: {_controller: GuideBundle:Security:login}

SecurityController.php

 class SecurityController extends Controller
    {
        /**
         * @Route("/auth", name="auth")
         */
        public function loginAction(Request $request)
        {
            //Here is the code, If I comment It nothing changes and I don't use here any MedicalStaff object
        }

    }

MedicalStaff.php 位于 GuideBundle\Entity 文件夹中

namespace GuideBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * MedicalStaff
 *
 * @ORM\Table(name="medical_staff")
 * @ORM\Entity(repositoryClass="GuideBundle\Repository\MedicalStaffRepository")
 */
class MedicalStaff
{
    //here are methods and properties
}

谁能说出会导致此类问题的原因?

【问题讨论】:

  • 你确定这是 Symfony 试图访问的控制器吗?错误消息表明它正在尝试提供使用参数转换器(失败)的路由。您可以使用debug:routerrouter:match 命令检查请求实际访问的路由或查看应用程序的日志。
  • 不是 404:“未找到 GuideBundle\Entity\MedicalStaff 对象。”
  • @ManoDestra 我在浏览器中收到 404 错误
  • @xabbuh 尝试 php bin/console router:match /auth 我得到“var\cache\dev/assetic/routing.yml”不包含有效的 UTF-8 YML。
  • 检查此文件/行是否有违规项:D:\Elya\КПИ\6 семестр\TSPP\mg\vendor\sensio\framework-extra-bundle\Request\ParamConverter\DoctrineParamConverter.php line 66,而不是您的控制器。

标签: php http-status-code-404 symfony


【解决方案1】:

这个YML

auth:
    path: /auth
    defaults: {_controller: GuideBundle:Security:login}

会和你的注释冲突

class SecurityController extends Controller
{
    /**
     * @Route("/auth", name="auth")
     */
    public function loginAction(Request $request)
    {
        //Here is the code, If I comment It nothing changes and I don't use here any MedicalStaff object
    }

}

使用一个而不是两个,检查你的配置,看看你应该使用哪个。

【讨论】:

    猜你喜欢
    • 2012-06-10
    • 2020-01-14
    • 2016-03-20
    • 2022-11-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 2016-12-02
    • 1970-01-01
    相关资源
    最近更新 更多