Symfony2:未找到"GET/lucky/number"的路由. [英] Symfony2: No route found for "GET /lucky/number"

查看:124
本文介绍了Symfony2:未找到"GET/lucky/number"的路由.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以新手身份开始教程,一切正常,直到:

I start the tutorial (as newbie) and everythings works fine till:

http://symfony .com/doc/current/book/page_creation.html#creating-a-page-route-and-controller 在步骤创建页面:路由和控制器

我创建了一个名为/var/www/html/[projekt]/src/AppBundle/Controller/LuckyController.php

但是当我打开 http://[Server-IP]:8000/app_dev.php/lucky/number 总是得到404:

but when I open http://[Server-IP]:8000/app_dev.php/lucky/number is always get a 404:

No route found for "GET /lucky/number"
404 Not Found - NotFoundHttpException
1 linked Exception: ResourceNotFoundException »

[2/2] NotFoundHttpException: No route found for "GET /lucky/number"   +
[1/2] ResourceNotFoundException:    +

routing.yml

routing.yml

app: 
    resource: "@AppBundle/Controller/" 
    type: annotation

控制器

namespace AppBundle\Controller; 

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;

class LuckyController 
{ 

    /**
     * @Route("/lucky/number") 
     */
    public function numberAction() 
    { 
        $number = rand(0, 100);
        return new Response( '<html><body>Lucky number: '.$number.'</body></html>' ); 
    }
}

不知道错误在哪里...

No idea where is the mistake...

错误-未捕获的PHP异常Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException:在/var/www/html/[Symfony-Folder]/app/中找不到"GET/lucky/number"的路由" cache/dev/classes.php第2061行

php app/console debug:route
 [router] Current routes
 Name                     Method Scheme Host Path
 _wdt                     ANY    ANY    ANY  /_wdt/{token}
 _profiler_home           ANY    ANY    ANY  /_profiler/
 _profiler_search         ANY    ANY    ANY  /_profiler/search
 _profiler_search_bar     ANY    ANY    ANY  /_profiler/search_bar
 _profiler_purge          ANY    ANY    ANY  /_profiler/purge
 _profiler_info           ANY    ANY    ANY  /_profiler/info/{about}
 _profiler_phpinfo        ANY    ANY    ANY  /_profiler/phpinfo
 _profiler_search_results ANY    ANY    ANY  /_profiler/{token}/search/results
 _profiler                ANY    ANY    ANY  /_profiler/{token}
 _profiler_router         ANY    ANY    ANY  /_profiler/{token}/router
 _profiler_exception      ANY    ANY    ANY  /_profiler/{token}/exception
 _profiler_exception_css  ANY    ANY    ANY  /_profiler/{token}/exception.css
 _configurator_home       ANY    ANY    ANY  /_configurator/
 _configurator_step       ANY    ANY    ANY  /_configurator/step/{index}
 _configurator_final      ANY    ANY    ANY  /_configurator/final
 _twig_error_test         ANY    ANY    ANY  /_error/{code}.{_format}
 homepage                 ANY    ANY    ANY  /

推荐答案

我刚刚添加了

<?php

到文件"LuckyNumberController",它的工作原理....真的很奇怪.

to the file "LuckyNumberController" and it works.... really strange.

谢谢大家

这篇关于Symfony2:未找到"GET/lucky/number"的路由.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆