Reputation: 7396
I'm looking to add the ability to resolve database-stored pages to a symfony 2.0 project. I'm curious however as to when is the best time to hook this functionality.
According to the Symfony 2 lifecycle, a router is asked to produce a controller (callable). Is there any way or anywhere that I can effectively create my own router that can select and produce a different controller with different configuration options?
Ideally I'd like to allow this routing mechanism to also pass on routes it can't fulfill. That way symfony can continue to behave as normal with stuff like 404 behaviour, etc...
Upvotes: 3
Views: 314
Reputation: 4336
Yes. You can implement a class that implements Symfony\Component\Routing\RouterInterface
-- read over the classes in Symfony\Bundle\FrameworkBundle\Routing
to see an example of an implementation.
You might have to do a good bit of digging to get it done, as there's not a whole lot of documentation on custom routers and it's (presumably) an unfamiliar codebase, but all of the Symfony2 code I've seen follows more or less the same pattern, and it gets easier to know where to look and what you need to do to override / implement custom parts quickly. And the code is pretty clean, which is a huge plus.
I don't know the details of what exactly would be required for your implementation, maybe someone else who knows more specifics can expand. However, I do know that it's not impossible, and for the most part if you implement classes that fulfill the interface requirements you see in Symfony\Component\Whatever
sanely you'll be able to implement what you want.
Upvotes: 4