Welcome Guest, Not a member yet? Register   Sign In
Route alias' like some other MVC frameworks (pylons, etc)
#1

[eluser]Unknown[/eluser]
I have been working on a project using Pylons (MVC for Python). I think they do a great job of routing.

Here's an example:
Code:
map.connect('article', 'article/:author/:id.:format', controller='article', action='view',
            id='all', format='html',
            requirements=dict(id='\d+', format='(rss|html|xml)'))

then in my views or controllers i never have to specify the true url ("/article/__author__/__id__"), but instead can do something like:
Code:
h.url_for('article', author='me', id='3')
using the web helpers util.


Basically, has anyone come up with a solution to use alias' for routes. It becomes more portable and receptive to change if something has to change all my links simply point to an alias.
#2

[eluser]Randy Casburn[/eluser]
Short answer: No. this is a clone of Ruby on Rails "Named Routes". If you do a search on these terms you should find some topics discussing these things.

Randy
#3

[eluser]Colin Williams[/eluser]
Seems like the real feature here, and correct me if I'm wrong, is that second part where the view can produce a URL without needing to know the proper format. I like that a lot. The first part seems straight-forward enough with CI routes.

Seems like all you need to do is introduce the right conventions to defining routes (like a unique syntax), then extend the URI class to understand and make use of the convention. Another option is to extend the Router class and revamp how CI routes are defined in routes.php (like with a map_connect() function, for example).

Anyone gonna tackle it? Doesn't seem too challenging (what ever does from the start!?)
#4

[eluser]nmweb[/eluser]
CakePHP has it so it's possible and quite handy in fact. Change a url and all links change along. Python has an edge over php in this case though with syntax and named arguments.
#5

[eluser]Rick Jolly[/eluser]
There seems to be a movement toward complexity lately. What happened to convention over configuration? With CI's routing, I don't need to define a route in most cases - less work and maintenance. Sure, with this method you may be able to change a link in only one place, but how often must you change links?
#6

[eluser]Randy Casburn[/eluser]
My back-o-the-mind kind of thought has been in the same place Rick. Just can't put that much thought into this right now. I've been wondering if all these "feature sets" folks site from other platforms ("but everyone else does it") we've been discussing lately aren't "exactly" why the other platforms aren't as streamlined as CI.

But that is just me thinking out loud. Named routes would be one of those that I think would slow things down from looking at an implementation. I was looking into extending the router class to do this and it got too big based on my work load right now.

Randy
#7

[eluser]Colin Williams[/eluser]
Quote:What happened to convention over configuration?

Well, routes themselves are already configuration over convention (the controller/method/id convention). Doing names routes is certainly another level of configuration, but could provide a nice layer of abstraction. Is it something I would personally employ? Not so sure. But it might fit nicely into other CodeIgniter's tool set.
#8

[eluser]Rick Jolly[/eluser]
[quote author="Colin Williams" date="1218069338"]
Quote:What happened to convention over configuration?

Well, routes themselves are already configuration over convention (the controller/method/id convention).[/quote]
Edit: Yes, of course the routes config file is a config file.
#9

[eluser]Randy Casburn[/eluser]
Come on Rick - You are correct that in its default, non-configured, out-of-the-box way, it's convention for CI. But I think Colin is referring to actually USING routes beyond the default. As in something close to the OPs intent. That would certainly be "configuration" thing...right?
#10

[eluser]Rick Jolly[/eluser]
Come on Randy. Do we really need to state the obvious? We're all at least of average intelligence aren't we?

My point is, in most cases, routes are unnecessary. Therefore, configuration is unnecessary. We can argue about fringe cases where routing configuration may be desireable.




Theme © iAndrew 2016 - Forum software by © MyBB