如何在symfony 2中设置自己的索引路由?

时间:2015-08-27 10:05:46

标签: php symfony

我的问题是我无法将控制器设置为主页。我一直在搜索,我找到了this,但是当我在生产环境中使用它时它不起作用。它只是使用开发环境。

这是我的routing.yml:

homepage:
path: /
defaults: { _controller: DictionaryBundle:Grid:index}

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

dictionary:
resource: @AppBundle/DictionaryBundle/Controller/
type:     annotation


fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"`

这是我的路由routing_dev.yml:

_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

homepage:
path: /
defaults: { _controller: DictionaryBundle:Grid:index}

这是我的职责:

/**
 * @Route("/{lang}", name = "showTranslationsGrid", defaults={"lang":"-"}, 
 * requirements={"lang":"-|en|fr|pt|it"})
 * @Template("AppBundle:Dictionary:grid.html.twig")
 * Renderiza la vista grid.html.twig que se encarga de generar el grid y cargar los datos
 */
public function indexAction($lang = "-")
{
    //utilizamos el servicio para obtener los belong
    $belongs = $this->forward('dictionary_util:getBelongsAction')->getContent();
    $languages = $this->forward('dictionary_util:getLanguagesAction')->getContent();
    $langs=json_decode($languages,true );

    return array('lang' => $lang, 'belongs'=> $belongs ,'languages'=> $languages );   
}

所以,任何人都知道为什么在app / Resources / views / default中生成环境中的index.html.twig而不是使用我的控制器并像dev环境一样渲染我的模板? 我还删除了tutorial之后的AcmeDemoBundle,我已经多次清除了chache。

我正在使用symfony 2.几天前我已经更新到symfony 2.7了。

0 个答案:

没有答案