Setting index route in Symfony 2

前端 未结 6 922
孤街浪徒
孤街浪徒 2021-01-22 00:59

I\'ve got Symfony2 installed, and a mostly working site, the only issue is I don\'t know how to set a default route. Currently, I access my index and other routes with the follo

相关标签:
6条回答
  • 2021-01-22 01:27

    Great Docs:

    How to Configure a Redirect without a custom Controller

    Routing

    0 讨论(0)
  • 2021-01-22 01:35

    I used below code to set home page route.It's working fine

    Symfony version : Symfony 3.2.8

    homepage:
        path:   /
        defaults:  { _controller: AppBundle:Home:index}
    
    0 讨论(0)
  • 2021-01-22 01:39

    I solved this problem by just removing the following from routing_dev.yml

    _welcome:
        pattern:  /
        defaults: { _controller: AcmeDemoBundle:Welcome:index }
    

    That is assuming you have setup a default / route in a routing.yml file or by defining the route in a controller like:

    /**
     * @Route("/")
     * @Template()
     */
    public function indexAction()
    {
        return array('name' => '1');
    }
    
    0 讨论(0)
  • 2021-01-22 01:49

    For me Symfony 4.1.x

    Edit the file

    # app/config/routes.yaml
    index:
        path: /
        controller: App\Controller\YourIndexController::yourIndexFunction
    

    There's App\Controller is the namespace you declare at the start of the Controller class, and after is your class name and method name to route to.

    0 讨论(0)
  • 2021-01-22 01:51

    Just create a route that maps to the / pattern :

    # app/config/routing.yml
    homepage:
        pattern:   /
        defaults:  { _controller: AcmeHomeBundle:home:show }
    

    This will route to whatever controller you specify.

    0 讨论(0)
  • 2021-01-22 01:51

    The answer given by ManseUK is very much helpful but I have little elaboration

    1)

    # app/config/routing.yml
    homepage:
        pattern:   /
        defaults:  { _controller: AcmeHomeBundle:home:show }
    

    2) rename the app_dev.php to index.php and this will route to the home page automatically

    0 讨论(0)
提交回复
热议问题