I'm newbi with symfony, i'm trying to add a new page to the demo application, I'm following this tuto
I added this controller src/AppBundle/Controller/LuckyController.php
// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
class LuckyController extends Controller
{
/**
* @Route("/lucky/number")
*/
public function numberAction()
{
$number = rand(0, 100);
return new Response(
'<html><body>Lucky number: '.$number.'</body></html>'
);
}
}
app/console router:debug return:
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
admin_index GET ANY ANY /{_locale}/admin/post/
admin_post_index GET ANY ANY /{_locale}/admin/post/
admin_post_new GET|POST ANY ANY /{_locale}/admin/post/new
admin_post_show GET ANY ANY /{_locale}/admin/post/{id}
admin_post_edit GET|POST ANY ANY /{_locale}/admin/post/{id}/edit
admin_post_delete DELETE ANY ANY /{_locale}/admin/post/{id}
blog_index ANY ANY ANY /{_locale}/blog/
blog_index_paginated ANY ANY ANY /{_locale}/blog/page/{page}
blog_post ANY ANY ANY /{_locale}/blog/posts/{slug}
comment_new POST ANY ANY /{_locale}/blog/comment/{postSlug
}/new
app_lucky_number ANY ANY ANY /{_locale}/lucky/number
security_login_form ANY ANY ANY /{_locale}/login
security_login_check ANY ANY ANY /{_locale}/login_check
security_logout ANY ANY ANY /{_locale}/logout
homepage ANY ANY ANY /{_locale}
When i navigate to http://127.0.0.1:8000/app_dev.php/lucky/number, i got this error
NotFoundHttpException: No route found for "GET /lucky/number"
My routing.yml
app:
resource: @AppBundle/Controller/
type: annotation
prefix: /{_locale}
requirements:
_locale: %app_locales%
defaults:
_locale: %locale%
# These lines define a route using YAML configuration. The controller used by
# the route (FrameworkBundle:Template:template) is a convenient shortcut when
# the template can be rendered without executing any logic in your own controller.
# See http://symfony.com/doc/current/cookbook/templating/render_without_controller.html
homepage:
path: /{_locale}
requirements:
_locale: %app_locales%
defaults:
_controller: FrameworkBundle:Template:template
template: 'default/homepage.html.twig'
_locale: "%locale%"
Thanks.