Re: [Cppcms-users] URL dispatching help
Brought to you by:
artyom-beilis
|
From: Troy W. <dr...@gm...> - 2013-05-08 04:00:44
|
Thank you all very much. It's now clear to me what URL mapping is and the problem it solves! On Tue, May 7, 2013 at 4:37 PM, Artyom Beilis <art...@ya...> wrote: > none of those in my code, or any other call to mapper(), yet the > application seems to work so far! > > > > > >Perhaps the problem is that I'm generating all the HTML code in CppCMS > templates and none in C++ functions. Is URL mapping relevant if I'm only > using templates to output HTML? I assume it is, because the documentation > states: > > Such system allows using "url" tag in templates system easily as" > > > > <a href="<% url "/news/article" using article id %>" >...</a> > > > > > > > >But I've been using something like: > > <a href="/news/<%= article.id %>">...</a> > > > > > >Which appears to work fine. I'm presuming there's some problem in my > usage that URL mapping solves? > > > > Now this is actually a question that is relevant... > > > I'll explain - lets see some examples > > Consider you are developing a generic application that can be installed in > different location. For example: > > www.website.com/coolnews/news/10 > www.website.com/my/news/10 > www.website.com/news/10 > > Consider you need to have some generic options in URL like language for > example > > www.website.com/my/news/ru/10 > www.website.com/my/news/en/10 > > Now your URL generation becomes > > > <a href="<%= root_url %>/news/<%= lang %>/<%= article.id %>" > ...</a> > > More than that, consider you have URL like > > /wiki/this%20my%20title > > i.e. you have native text than it should be > > <a href="<%= root_url %>/news/<%= lang %>/<%= article.id | urlencode > %>" > ...</a> > > Now put it in every possible corner - not easy. > > So, this what url mapping you solves - it provide easy, generic and > abstract way to generate URLs such that > > 1. You can change them easily and actual URL format is located in one > place not all over the code > 2. You can manipulate various different properties globally (locale/root > etc) > 3. The default filter is URL encode and not HTML escape that suites URL > generation much better. > > > > > In my first applications I used the approach you had started with but it > becomes much harder > to maintain - that is why url mapper was developed. > > > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.com/ > CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ > > > ------------------------------------------------------------------------------ > Learn Graph Databases - Download FREE O'Reilly Book > "Graph Databases" is the definitive new guide to graph databases and > their applications. This 200-page book is written by three acclaimed > leaders in the field. The early access version is available now. > Download your free book today! http://p.sf.net/sfu/neotech_d2d_may > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |