I am trying to route to a category.

I currently have:

foo:
    path:  /foo/{page}.{_format}
    defaults: { _controller: Bundle:Main:foo, page: "" }

when I try to access mydomain.com/foo/ I am getting a error saying to route is not found.

How can I fix this?

Thanks.

有帮助吗?

解决方案

The errors happens because you have a dot in your route, and the routing expect to find a dot in the route, but you try to access to mydomain.com/foo/, which has no dot. If you want to access to mydomain.com/foo/, you can define another route as below:

foo:
    path:  /foo
    defaults: { _controller: Bundle:Main:foo, page: "" }

In this way, your routing doesn't expect the dot in the route and you specify the default value for the page variable.

I've been testing your example and I've seen that you can avoid to do my previous example simply defining the _format variable as below:

foo:
    path:  /foo/{page}.{_format}
    defaults: { _controller: Bundle:Main:foo, page: "", _format: html }

And if you try to access to mydomain.com/foo/, Symfony throws an exception, but if you access to mydomain.com/foo without the last bar, the route it's correctly managed.

其他提示

You need to provide default values for your route parameters. You can read about it in official docs here - http://symfony.com/doc/current/book/routing.html#adding-requirements

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top