我最近将我的symfony应用程序从3.2.4更新为3.4.11 更新后,如果URL中缺少语言环境,则应用程序将无法路由到indexAction。使用默认语言环境,应该只添加缺少的语言环境并路由到indexAction
示例: http://127.0.0.1:8000->显示“ symfony准备就绪”起始页 http://127.0.0.1:8000/de->显示实际的indexAction
我正在使用注释进行路由,这是我的routing.yml
#routing.yml
app:
resource: "@AppBundle/Controller/"
type: annotation
prefix: /{_locale}
requirements:
_locale: '%app_locales%'
defaults:
_locale: '%locale%'
这是我的控制器,带有indexAction并路由“ /”
#AppController.php
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Content;
use AppBundle\Entity\ContentsNav;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
class AppController extends Controller
{
/**
* @Route("/", name="app_index")
* @Method("GET")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$config = $em->getRepository('AppBundle:Configuration')->findOneBy([]);
return $this->render('public/app/app_index.html.twig', ['config' => $config]);
}
这是什么问题?
---编辑---
根据要求,这是php bin /控制台debug:router的输出
----
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_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_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
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
app_blog_index GET ANY ANY /{_locale}/blog/
app_blog_index_paginated GET ANY ANY /{_locale}/blog/{page}
app_blog_category GET ANY ANY /{_locale}/blog/{slug}
app_blog_category_paginated GET ANY ANY /{_locale}/blog/{slug}/{page}
app_blog_post GET ANY ANY /{_locale}/blog/{slugcategory}/{slug}
admin_home GET ANY ANY /{_locale}/admin/
admin_edit_configuration GET|POST ANY ANY /{_locale}/admin/configuration/
admin_category_home GET ANY ANY /{_locale}/admin/categories/
admin_category_new GET|POST ANY ANY /{_locale}/admin/category/new/
admin_category_edit GET|POST ANY ANY /{_locale}/admin/category/{id}/edit/
admin_category_translations GET ANY ANY /{_locale}/admin/category/{id}/translations/
admin_category_translation_add GET|POST ANY ANY /{_locale}/admin/category/{id}/translations/add/{localeCategory}/{localeTranslation}
admin_category_translation_edit GET|POST ANY ANY /{_locale}/admin/category/{idParent}/translations/{id}/edit/{localeCategory}/{localeTranslation}
admin_category_delete DELETE ANY ANY /{_locale}/admin/category/{id}/delete/
admin_content_home GET ANY ANY /{_locale}/admin/contents/{page}/{type}
admin_content_new GET|POST ANY ANY /{_locale}/admin/content/{type}/new/
admin_content_edit GET|POST ANY ANY /{_locale}/admin/content/{id}/edit/
admin_content_translations GET ANY ANY /{_locale}/admin/content/{id}/translations/
admin_content_translation_add GET|POST ANY ANY /{_locale}/admin/content/{id}/translations/add/{localeContent}/{localeTranslation}
admin_content_translation_edit GET|POST ANY ANY /{_locale}/admin/content/{idParent}/translations/{id}/edit/{localeContent}/{localeTranslation}
admin_content_delete DELETE ANY ANY /{_locale}/admin/content/{id}/delete/
admin_render_blueprint ANY ANY ANY /{_locale}/admin/content/render/blueprint/{$template_name}/{id}/{i}
admin_file_home GET ANY ANY /{_locale}/admin/files/
admin_file_home_page GET ANY ANY /{_locale}/admin/files/page-{page}
admin_file_upload GET|POST ANY ANY /{_locale}/admin/file/upload
admin_file_delete GET ANY ANY /{_locale}/admin/file/{filename}/delete/
admin_nav_home ANY ANY ANY /{_locale}/admin/navs/
admin_nav_new ANY ANY ANY /{_locale}/admin/nav/new/
admin_nav_new_remove_element ANY ANY ANY /{_locale}/admin/nav/new/{idRemove}
admin_nav_edit ANY ANY ANY /{_locale}/admin/nav/edit/{id}
admin_nav_edit_remove_element ANY ANY ANY /{_locale}/admin/nav/edit/{id}/{idRemove}
admin_nav_delete DELETE ANY ANY /{_locale}/admin/nav/{id}/delete/
admin_nav_translations GET ANY ANY /{_locale}/admin/nav/{id}/translations/
admin_nav_translation_generate GET ANY ANY /{_locale}/admin/nav/{id}/translations/generate/{localeNav}/{localeTranslation}
admin_nav_translation_update GET ANY ANY /{_locale}/admin/nav/{id}/translations/update/{localeNav}/{localeTranslation}
login_route ANY ANY ANY /{_locale}/login
login_check_route ANY ANY ANY /{_locale}/login_check
logout_route ANY ANY ANY /{_locale}/logout
password_recovery ANY ANY ANY /{_locale}/passwordrecovery
password_reset ANY ANY ANY /{_locale}/passwordreset/{token}
admin_user_home GET ANY ANY /{_locale}/admin/users/
admin_user_new GET|POST ANY ANY /{_locale}/admin/user/new/
admin_user_edit GET|POST ANY ANY /{_locale}/admin/user{id}/edit/
admin_user_delete DELETE ANY ANY /{_locale}/admin/user{id}/delete/
admin_edit_profile GET|POST ANY ANY /{_locale}/admin/user/profile/
app_index GET ANY ANY /{_locale}/
app_page GET ANY ANY /{_locale}/{slug}
-----