Hello,For your consideration, here is a proof of concept prototype for using named routes. It uses the Options field in the route definitions, which means it is fully backward compatible with existing dispatch.conf files. (the attached e_dispatcher_standalone is functionally the same as the e_dispatcher module, but I removed all references to external modules for simpler testing)
In the prototype you can define named routes as: (drawing ideas from symfony-project's routing)
- patterns in the URL are marked with :name, - their regexp is given within the options as well as the route's name.(for now a preprocessor converts routes given in this form back to the original regexp format of dispatch.conf files)
{dynamic, "/blog/:user_id/:post_no/read", {blog, read}, [{route_name, user_post_read}, {patterns, [ {user_id, "[a-zA-Z_0-9]+"}, {post_no, "[0-9]+"} ]} ] }. Dispatching works as expected: > e_dispatcher_standalone:dispatch("/blog/zed/108/read"). Dispatcher params: [{post_no,"108"},{user_id,"zed"}] {blog,read,[]}Reverse dispatching requires the route name and values for each pattern as input: > e_dispatcher_standalone:url_for(user_post_read, [{user_id, zed}, {post_no, 1}]).
"/blog/zed/1/read"Missing or superfluous parameters are detected and an error is thrown. Furthermore each parameter is matched against its regexp's: > e_dispatcher_standalone:url_for(user_post_read, [{user_id, z...@home}, {post_no, 1}]).
{error,{invalid_parameter,user_id}}Additionally it would also be possible to create an url_for/1, taking only the list of parameters as an input. This function would return the first route to match the given parameters...
Kindest regards, Zoltan. Michal Ptaszek wrote:
Hello, There is no such thing as reverse dispatching: the main reason for that is there might be many routes that lead to the one controller, for example: {dynamic, "^/index\.html$", {home, main}}. {dynamic, "^/$", {home, main}}. {dynamic, "^/home$", {home, main}}. However, you can still access the URL user entered getting it from the process dictionary: wpart:fget("__path") (note that there is a double underscore character). ----- "Zoltan Lajos Kis" <ki...@tmit.bme.hu> wrote:Hi all, I might be missing a point, but how do I refer to the dynamic routesin dispatcher.conf from within my content?Taking this example route from the wiki is there a function that does something like the following function? {dynamic, "^/blog/post/(?<post_no>[0-9]+)$", {blog, display_post}}.route:create({blog, display_post}, [{post_no, "23"}]) -> "/blog/post/23"Kindest regards, Zoltan.Best regards,
named_routes.tar.gz
Description: application/gzip
------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com
_______________________________________________ Erlangweb-users mailing list Erlangweb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/erlangweb-users http://www.erlang-web.org/