Setting index route in Symfony 2

Deadly 提交于 2019-12-02 00:19:46

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.

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}

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');
}

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!