Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony路由混乱_Php_Symfony_Routing - Fatal编程技术网

Php Symfony路由混乱

Php Symfony路由混乱,php,symfony,routing,Php,Symfony,Routing,嗨,伙计们,我是个笨蛋,请容忍我 我有这样一个简单的控制器 <?php namespace Sites\AllBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; // these im

嗨,伙计们,我是个笨蛋,请容忍我

我有这样一个简单的控制器

<?php

namespace Sites\AllBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

// these import the "@Route" and "@Template" annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;


class SitesController extends Controller
{
    /**
     * @Route("/", name="_all")
     * @Template()
     */
    public function indexAction()
    {       
        return array('name' => 'sssssss');
    }

    /**
     * @Route("/wow",)
     * @Template()
     */
    public function wowAction()
    {       
        return array('wow' => 'sssssss');
    }

}
app/config/routing.yml中的路由如下

sites_all:
    resource: "@SitesAllBundle/Resources/config/routing.yml"
很简单,而且很好用……但我不想加上这个

@Route("/")
在每个函数的注释中,如果我删除它,它将不起作用

是否有办法使控制器/功能直接指向该功能


谢谢各位,如果我理解正确的话,您要求的是一种由控制器和操作名称定义路由的方法,而不是必须为每个操作指定路由,对吗

Symfony2不提供现成的功能,但可以通过第三方捆绑包实现

安装并启用捆绑包后,您可以按如下方式设置routing.yml:

_all:
    resource: "@SitesAllBundle"
    type:     default
    prefix:   /
然后,如果您使用

app/console router:debug
您应该有如下内容:

[router] Current routes
Name                                                   Method Pattern
sites_allbundle.sites.index                            ANY    /sites/
sites_allbundle.sites.wow                              ANY    /sites/wow
哪个匹配/{prefix}/{controller}/{action}

希望有帮助

[router] Current routes
Name                                                   Method Pattern
sites_allbundle.sites.index                            ANY    /sites/
sites_allbundle.sites.wow                              ANY    /sites/wow