0

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.

3
  • You are mixing route annotation and routing in yaml, I don't know how mush this is bad for Symfony but definitely is not good for your project structure. I suggest you to one or the other in each bundle. Commented Aug 27, 2015 at 10:35
  • Anyway, use app/console --env=prod router:debug to see all configured route in production enviroment, and app/console --env=prod router:match / to see the actual route which is chosen Commented Aug 27, 2015 at 10:36
  • Ok thanks =) this could be one the causes of my problem. Because I didn't know about this Default controller using annotation. Thank you again. Commented Aug 28, 2015 at 10:56

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.