Hi there!
Very interesting questions about the routing. Let me answer them both (or
ask more questions):
1. Routing of nested slugs
This is possible, but there are several different approaches that I know of.
I've never been *totally* satisfied, so hopefully someone will follow up
with something more intelligent.
--> Method #1: Create a "catch-all" route, matching the different possible
"levels" you have, with defaults listed for each of the slugs:
document:
pattern: /{slug}/{slug2}/{slug3})
defaults: { _controller: Acme:Foo:show, slug1: ~, slug2: ~, slug3: ~ }
You'd then have a method somewhere in your model to retrieve the object
(inside the controller) from your database based on the different slugs.
Exactly If your "Document" entities have parent relationships, this would
entail matching a Document's slug to the last slug, its parent to the
second-to-last slug, etc. One downside to this approach is that the route
will catch *everything*, so it'll need to be at the bottom of your routing.
--> Method #2: Create a "Document router loader" that would actually load
routes using the objects from your Document entity. This would result in a
number of exact routes being generated dynamically. For example, one route
might "look" like this:
document_about_us:
pattern: /about-us
default: { _controller: Acme:Foo:show, id: 17 }
The advantage is that you have the id at your disposal and you have exact
matching in your routing file (no catch-all route). One disadvantage is that
you have to manage removing the routing cache file upon Document changes so
that it can regenerate. You'll also need a new template helper to generate
your routes. This helper would need to be smart enough to figure out the
route name given a Document object. For example, you might prefix all routes
with "document_" and then replace dashes (-) with underscores (_). The final
product would still look basically the same:
{{ doc_path($document) }}
If anyone has any better solutions, I'd love to know. This is a very common
routing problem to solve.
2. Routing nested sets
This looks interesting, but I'm not sure. I think the @homepage/news is
interesting, but - other than the _schema, _locale and maybe _format
requirements - having the requirements cascade doesn't necessarily make
sense (it might make sense in some cases, maybe not in others). So, I think
this is cool (and wouldn't be very hard to implement), but I'm torn as to
whether or not it would be *needed* or unnecessary.
By the way, even if this weren't in core, you could of course override
Symfony's core YAML routing loader and add in this type of functionality.
You could even add in your own loader, and register a new extension for
routing files that take advantage of this functionality (e.g. .yml2).
Thanks!
Ryan Weaver
US Office Head & Trainer - KnpLabs - Nashville, TN
http://www.knplabs.com <http://www.knplabs.com/en>
http://www.thatsquality.com
Twitter: @weaverryan
On Sat, May 14, 2011 at 6:18 AM, [email protected] <[email protected]>wrote:
> Hi,
>
> our company would like to switch to Symfony2 as its major development
> platform, so we are currently evaluating it against our needs. As far
> as I can seen the following needs regarding routing might be
> problematic with Symfony2:
>
> 1. Routing of nested slugs
> Imagine we have a entity called "document", that is organised
> hierarchically, so each document (except the root) has a parent
> document. Now we would like the route to a controller displaying this
> document a combination of the slugs of all documents along the path.
> Example:
> "homepage" => /
> "about-us" => /about-us/
> "team" => /about-us/team/
> "news" => /news/
> ...
>
> The result of the rout /about-us/team/ should then be something like
> {_controller: documentDisplayController, id: 17}, with 17 being the id
> of the document with the slug "team". Also, calling "generateUrl" with
> something like ('documents', array('id' => 18)) should give "/
> news/" (with 18 being the id of the document with the slug "news"..).
>
> 2. Routing nested routes
> At the moment we are able to define routes, that are kind of "below
> other routes". Example (our current routing syntax is kind of similar
> to Symfony2, the @ refers to a route being already defined):
> homepage:
> pattern: /
> defaults: {_controller: homepageController:index}
> extranet:
> pattern: @homepage/extranet/
> defaults: {_controller: extranetController:index}
> requirements:
> _scheme: https
> extranet-news:
> pattern: @extranet/news/
> defaults: {_controller: extranetController:news}
>
>
> With this, it would be possible to call the following urls:
> / => {_controller: homepageController:index}
> /extranet/ => {_controller: extranetController:index,
> _scheme: https}
> /extranet/news/ => {_controller: extranetController:news, _scheme:
> https}
>
>
> I know that you can enforce https for a whole part of your website
> with the security component, but I just wanted to give a quick example
> of a route default / requirement being "inherited".
>
> Could anyone being more into Symfony2 routing comment on this?
>
> Kind regards,
> Per
>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en
>
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en