当前位置:  开发笔记 > 编程语言 > 正文

找不到Symfony 404

如何解决《找不到Symfony404》经验,为你挑选了2个好方法。

我是symfony的新手.

我做了:

rm -rf app/cache/*
rm -rf app/logs/*

然后:

sudo setfacl -R -m u:www-data:rwx -m u:user :rwx app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:user:rwx app/cache app/logs

ls -al 得到:

drwxrwxrwx 3 user user  1024 ???   29 00:06 cache(cache is on green background)
drwxrwxrwx 2 user user  1024 ???   29 00:06 logs(logs is on green background)

现在我正在尝试访问/Symfony/web/app_dev.php - 它显示:

加载Web调试工具栏时出错(404:Not Found).

你想打开探查器吗?

当我单击"确定"时,它会重定向到

/Symfony/web/app_dev.php/_profiler/bd8604738ac7af3c9d0611ea12076f0f62422601

找不到404文件..

这是app/logs/dev.log

[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2013-05-29 00:12:29] request.INFO: Matched route "_welcome" (parameters: "_controller": "Acme\DemoBundle\Controller\WelcomeController::indexAction", "_route": "_welcome") [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\Fragment\FragmentHandler::onKernelRequest". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DeprecationLoggerListener::injectLogger". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Acme\DemoBundle\EventListener\ControllerListener::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\Fragment\FragmentHandler::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse". [] []
[2013-05-29 00:12:29] event.DEBUG: Notified event "kernel.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate". [] []

我没有找到解决方案,请帮忙

编辑:

Routing_dev.xml

_welcome:
    pattern:  /
    defaults: { _controller: AcmeDemoBundle:Welcome:index }

_demo_secured:
    resource: "@AcmeDemoBundle/Controller/SecuredController.php"
    type:     annotation

_demo:
    resource: "@AcmeDemoBundle/Controller/DemoController.php"
    type:     annotation
    prefix:   /demo

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /_profiler

_configurator:
    resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
    prefix:   /_configurator

_main:
    resource: routing.yml

config_dev.xml

imports:
    - { resource: config.yml }

framework:
    router:   { resource: "%kernel.root_dir%/config/routing_dev.yml" }
    profiler: { only_exceptions: false }

web_profiler:
    toolbar: true
    intercept_redirects: false

monolog:
    handlers:
        main:
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug
        firephp:
            type:  firephp
            level: info
        chromephp:
            type:  chromephp
            level: info

assetic:
    use_controller: true

#swiftmailer:
#    delivery_address: me@example.com

app_dev.php

loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

TautrimasPaj.. 10

我的问题是kernel.terminate事件执行超过10秒.很难发现,因为探查者没有测量此事件的时间表.

当我意识到这一点时,我立即将问题缩小到我的一个具有异常长时间运行__construct方法的事件监听器.此延迟配置文件打印时间过长,导致5次重试后出现Javascript超时错误.

在修复了违规的听众后,kernel.terminate事件进展得很快,问题立即消失了.

您可以使用快速查看附加的侦听器bin/console debug:event-dispatcher kernel.terminate.



1> TautrimasPaj..:

我的问题是kernel.terminate事件执行超过10秒.很难发现,因为探查者没有测量此事件的时间表.

当我意识到这一点时,我立即将问题缩小到我的一个具有异常长时间运行__construct方法的事件监听器.此延迟配置文件打印时间过长,导致5次重试后出现Javascript超时错误.

在修复了违规的听众后,kernel.terminate事件进展得很快,问题立即消失了.

您可以使用快速查看附加的侦听器bin/console debug:event-dispatcher kernel.terminate.



2> 小智..:

根据我自己的经验; 更改路由的标准行为时会发生此行为.例如,在我的情况下,我使用kernel.request监听器来创建一种语言检测机制,该机制应该根据用户/浏览器支持的语言为用户选择最佳语言.

我在app/config/routing.yml中的所有路由中使用了{_locale}前缀

some_route:
    resource: "@MyBundle/Resources/config/routing.yml"
    prefix:   /{_locale}/

通过这种方式,我能够在路由的开头快速添加语言代码,在我的侦听器类中,我将客户端重定向到以现有语言代码为前缀的路由,无论客户端是否请求具有或不具有语言环境的路由.

例如,如果我的网站只有"en"和"de"作为语言,并且如果用户请求

http://www.mysite.com/somepage

要么

http://www.mysite.com/fr/somepage

我正在将客户端重定向到

http://www.mysite.com/en/somepage

所以每当我的应用程序出错时,探查器路由都不知道这种情况,并试图从没有{_locale}前缀的路由中显示自己.这导致404错误.

解决方案很简单:

我打开app/config/routing_dev.yml文件并修改了所有路由,如下所示:

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /{_locale}/_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /{_locale}/_profiler

_configurator:
    resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
    prefix:   /{_locale}/_configurator

注意/ {_ locale}部分.

所以问题对我来说是固定的.

推荐阅读
雯颜哥_135
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有