Well, you can sort of have "loadable" modules. You can add a routing.xml to your module and include it using xincludes. That should solve most of your problems. If you want to enable or disable specific modules at runtime, use the module's settings.xml - it contains a setting named "enabled", set that to false, done.
However, pluggable modules require quite a bit more work: What about base classes for actions, views, models etc. This is easily solvable in a defined context (i.e "for all my applications") since I can enforce that all base classes meet certain requirements. It gets hard when you try to solve that "for all purposes". We have been discussing about the issues for quite a while, yet we haven't found any working solution. Anyways, you can sort of read routes from the database. You can create a streamwrapper that returns xml code and xinclude that. Stream wappers are supported in xinclude statements. I tried that approach for a CMS, gave up because no one ever used that feature. You could in theory change the routing to load all routes from the database but think about the consequences: Each and every request, whether it matches or not needs to build the whole routing tree from the database. Requests that don't match need to go through all of that. This is a massive overhead, even before your app has started up, pushing down your response times and stress-testing your database servers. This may be feasible for low-load sites but do low-load sites need dynamic routing? This is the kind of features that sounds like a killer at first sight, but think twice about it: Is that something you need? What do you need that for? There might just be a better solution for your use case. felix On Jan 5, 2010, at 12:07 PM, Guilherme Aiolfi wrote: > Dynamic URLs would allow some kind of self container modules: modules with > all its actions, views, models, routings. > > Something that is not possible today, I guess. The only part that can't be > done by module is its routings that has to be all into routings.xml. > > If I want to allow the admin of my site to e.g. load, unload, disable modules > dynamically, how should it be done? > > Being able to look for routings in the DB would improve the agavi flexibility > a lot. Is it possible? I mean, using an "unhacked" agavi? > > On Tue, Jan 5, 2010 at 8:20 AM, Felix Gilcher <[email protected]> > wrote: > In general, I fail to see the benefit of that. URLs are organized like > folders, each part can be represented as s sub-folder. How would you organize > your data: > > - Have one big folder and throw in all events and all galleries in the same > folder, just organized by name > - Have two subfolders named "events" and "galleries" and organize your data > in those two folders by name > > The first one roughly translates to your static routing example. The second > approach translates to something like the following (untested) routing config > > <route pattern="^/galleries" name="gallery" module="Galleries"> > <route pattern="^/(galname:\S+)" name=".gallery" action="Gallery"> > <route pattern="^$" name=".index" action=".Index" /> > </route> > </route> > > <route pattern="^/events" name="events" module="Events"> > <route pattern="^/(eventname:\S+)" name=".event" action="Event"> > <route pattern="^$" name=".index" action=".Index" /> > <route pattern="^edit/$" name=".edit" action=".Edit" /> > </route> > </route> > > That solves most of your matching problems. It also provides a natural place > where to hook in a "view all galleries" and "display upcoming events" page. > And as a bonus, search engines love well structured url schemata. > > If you're writing a CMS, you should at any point have a knowledge what kind > of item you're handling and thus be able to use the proper routes. All items > should by default use the canonical urls laid out by the routing scheme and > should always be retrievable by using that url. This provides the visitor > with a simple scheme of how urls are laid out and how to navigate the page. > You should also include a <link rel="canonical" ...> element in the head of > the page pointing to the canonical url for the item. However, sometimes the > user of the CMS wishes to assign additional shortcut urls to specific items > of any kind. There's multiple ways of solving that: > > - You can provide the user with a way to define a mapping from short url to > the canonical url and dynamically generate a rewrite config. That's probably > the fastest way since the webserver does all the rewriting, but its > technically a bit complex. You need to take extra care that the config is > valid, since breaking it would break the whole webserver config, you may need > to restart the webserver after changes were made, ... > > - Same as above, but don't generate a rewrite config. Have a catch-all route > at the end of the routing with a callback that resolves the short url and > redirect to the long url from there. This is a relatively simple solution, > however, the url changes for the user and it requires one extra roundtrip. > > - You can provide the user with an option to map a short url to any specified > item. Then, in the Error404 Action you can try and recover - look up the > short url in your mapping and forward to the appropriate action. This may > involve elaborate logic in the 404 action. No extra roundtrip for the > redirect, the url does not change. > > The last two options may put quite a bit of strain on your database server > since every false url (as in "does not point to a valid page") will result in > a database query. You may want to cache the mapping in a memcache server or > similar to speed things up > > Hope that helps > > felix > > > On Jan 5, 2010, at 10:39 AM, Michal wrote: > > > Hi, > > > > Is it possible to have routing determined (more or less) at runtime? > > I'm thinking that in a CMS-type app, a user might want to choose what > > a route maps to: say to a gallery action or an events calendar action. > > Each of these actions could have different sub-routes. Static-ly, I > > would do it something like (non-working example): > > > > <route pattern="^(galname:\S+/" name="gallery" module="gallery"> > > <route pattern="^$" name=".index" action="Index" /> > > </route> > > > > <route pattern="^(eventname:\S+)/" name="events" module="events"> > > <route pattern="^$" name=".index" action="Index" /> > > <route pattern="^edit/$" name=".edit" action="Edit" /> > > </route> > > > > The issue with the above example is that the "gallery" route would > > always be matched, and the "events" one would not. I need some way to > > dynamically choose at runtime which one. A few ideas: > > > > - Have a callback in each route. The callback would query the database > > (and possibly cache the result) to see if the current route should > > match. > > - Use a modified routing class. I'm not sure quite how to modify it though. > > - Dynamically generate routing.xml itself. This could either be on > > every request (somehow?), or just when a user makes a change. > > - Don't really use routing.xml at all: have a "catch all" route that > > maps to a "Control" action, that then processes the URL and forwards > > to the correct action. > > > > I'm not sure in which direction to go. Any suggestions? > > > > Michal. > > > > _______________________________________________ > > users mailing list > > [email protected] > > http://lists.agavi.org/mailman/listinfo/users > > -- Felix Gilcher Bitextender GmbH Paul-Heyse-Str. 6 D-80336 München T: +49 89 57 08 15 16 F: +49 89 57 08 15 17 M: +49 172 840 88 28 [email protected] http://www.bitextender.com/ Amtsgericht München, HRB 174280 Geschäftsführer: David Zülke, Florian Clever _______________________________________________ users mailing list [email protected] http://lists.agavi.org/mailman/listinfo/users
