Reputation: 440
My issue is that I can't set my controller as the homepage. I have been searching a bit and I found this but it doesn't work when I runt it in production environment. It just works using dev environment.
This is my 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"`
This is my routing 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}
And this is my function:
/**
* @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 );
}
So, anybody know why something is rendering index.html.twig in app/Resources/views/default in production environment instead of using my controller and rendering my template like dev environment does? I have also remove AcmeDemoBundle following this tutorial and I have cleared chache several times too.
I am working with symfony 2. I have updated to symfony 2.7 few days ago.
Upvotes: 0
Views: 931
Reputation: 440
The problem was the order of statements in rounting files. It was not working with production environment because homepage is at the top of the file, just below it refeers to the controllers inside AppBundle. There was DefaultController that came in default when I installed symfony (I though it only had AcmeDemoBundle). This controller was overriding previus declaration of homepage. I won't remove the question just to make clear that order matters specially if you are working with other people in the same proyect.
Upvotes: 2