Re: [Cppcms-users] What exactly url_mapper does?
Brought to you by:
artyom-beilis
|
From: Artyom B. <art...@ya...> - 2011-08-07 18:14:14
|
URL Mapper allows overloading the functions.
For example you may call
url("/my/app",category_id)
and
url("/my/app",category_id,page_no)
That are mapped as
map.assign("/app","/article/{1}")
map.assign("/app","/article/{1}/page/{2}")
In the case of main form page it just overloads the
cases where the URL represents the latest comments
or comments with paging.
flat_thread::flat_thread(cppcms::service &s) :
thread_shared(s)
{
dispatcher().assign(".*",&flat_thread::prepare,this,0);
mapper().assign("{1}");
}
Means that prepare function would receive as first parameter the 0
regular expression group on selection (Everything) and
for mapping it would convert its parameter to its representation
as is.
Most important take a look on how URLs are used in templates
forums.tmpl: <form action="<% url "/forums" %>" method="post" >
forums.tmpl: <a href="<% url "/forums" using next %>"><% gt "Next Page" %></a>
This is mapping of "forums" application with 0 or 1 parameter.
And this is how thread applications mapping is used:
thread.tmpl: <a href="<% url "/flat_thread" using thread_id %>"><% gt "Flat View"%></a>
thread.tmpl: | <a href="<% url "/tree_thread" using thread_id %>"><% gt "Tree View" %></a>
Regards,
Artyom Beilis
>________________________________
>From: Abhishek Kaushik <abh...@gm...>
>To: cpp...@li...
>Sent: Sunday, August 7, 2011 4:35 PM
>Subject: Re: [Cppcms-users] What exactly url_mapper does?
>
>Hi,
>
>Could you please explain me these differences regarding
>the message board example application?:
>
>forums::forums(cppcms::service &srv) :
>master(srv)
>{
> dispatcher().assign(".*",&forums::prepare,this,0);
> mapper().assign("{1}"); // with id
> mapper().assign(""); // default
>}
>
>AND
>
>flat_thread::flat_thread(cppcms::service &s) :
>thread_shared(s)
>{
> dispatcher().assign(".*",&flat_thread::prepare,this,0);
> mapper().assign("{1}");
>}
>
>
>I have referred the doxygen documentation, but still failed to make out much
>meaning regarding this particular problem.
>
>could you tell me as to why in forums constructor it was possible to have 2
>mapper().assign() one for "" and other for "{1}"
>
>whereas, in flat_thread, it has only 1 mapper().assign() statement
>and thats "{1}".
>
>What conditions tell us that it would require 2 or 1 assign statements?
>
>I fully understand the dispatcher but this mapper, I am unable to.
>
>Hope you understand my problem. Please let me know if I am missing
>the basics of anything, i will refer it.
>
>Thanks in advance for your reply.
>
>
>
>
>------------------------------------------------------------------------------
>BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
>The must-attend event for mobile developers. Connect with experts.
>Get tools for creating Super Apps. See the latest technologies.
>Sessions, hands-on labs, demos & much more. Register early & save!
>http://p.sf.net/sfu/rim-blackberry-1
>_______________________________________________
>Cppcms-users mailing list
>Cpp...@li...
>https://lists.sourceforge.net/lists/listinfo/cppcms-users
>
>
> |