문제

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