Answer the question
In order to leave comments, you need to log in
Is it possible to simplify routing in symfony?
It is necessary to make the same type of routing in symfony 2.8 for different pages.
Router debug itself:
The idea is that there will be more routes like /post, /comment. Perhaps there will also be another route like /best, /worst
Is it possible to simplify routing using inheritance? or what other options? or to write completely dynamic routing?
At the moment it looks terrible:
BlogBundle_best:
path: /best
defaults: { _controller: "BlogBundle:Best:index" }
methods: [GET]
BlogBundle_best_post:
path: /best/post
defaults: { _controller: "BlogBundle:Best:post", page: 1 }
methods: [GET]
BlogBundle_best_post_page:
path: /best/post/page/{page}
defaults: { _controller: "BlogBundle:Best:post" }
methods: [GET]
BlogBundle_best_post_period:
path: /best/post/{period}
defaults: { _controller: "BlogBundle:Best:postByPeriod", page: 1 }
methods: [GET]
requirements:
period: "ever|year|month|week|day"
page: \d+
Answer the question
In order to leave comments, you need to log in
// routing.yml
BlogBundle
resource: "BlogBundle.yml"
prefix: /
// BlogBundle.yml
BlogBundle_best:
resource: "BlogBundle_best.yml"
prefix: /best
// BlogBundle_best_post.yml
BlogBundle_best_post:
resource: "BlogBundle_best_post.yml"
prefix: /post
BlogBundle_best_comment:
resource: "BlogBundle_best_comment.yml"
prefix: /comment
// BlogBundle_best_post.yml
BlogBundle_best_post_period:
path: /{period} <-- real /best/post/{persiod}
...
BlogBundle_best_post_page:
path: /page/{page} <-- real /best/post/page/{page}
...
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question