Re: [Cppcms-users] what is the integer in url_dispatcher::asign for?
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-01-18 11:23:46
|
The number represents regular expression subexpression. Quoting reference doc from url_dispatcher: if regular expression is "^/page/(\\d+)/(\\w+)$" , exp1=2, and the url is "/page/13/to_be_or_not", then handler would be called with "to_be_or_not" as its first parameter So number represents a subexpression you want to capture and pass as a parameter to function. For example dispatcher().assign("/foo/(\\w+)/(\\w+)",&myclass::bar,this,2,1) For url /foo/bar/baz would call : bar("baz","bar") Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.sf.net/ CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ >________________________________ > From: Marcel Hellwig <ke...@co...> >To: cpp...@li... >Sent: Wednesday, January 18, 2012 11:48 AM >Subject: [Cppcms-users] what is the integer in url_dispatcher::asign for? > > >Hello everybody, > >I wonder about this method: >http://art-blog.no-ip.info/cppcms_ref_v0_99/classcppcms_1_1url__dispatcher.html#a92c984612be4b29e9e45b58cbe676f77 >this is (I think) the standard url assign method everybody uses. >In the tutorial of url mapping ( http://cppcms.sourceforge.net/wikipp/en/page/cppcms_1x_tut_url_mapping ) it says: "In the fourth line we connect the regular expression /number/(\d+) to the member function number of this instance that receives std::string as parameter, and 1st captured subexpression is passed to it." (4: "dispatcher().assign("/number/(\\d+)", &hello::number, this, 1);" ) >So i now think, what happens if you put instead of a 1 a 0 to the method, like in the "message_board" example: >/message_board/apps/thread.cpp:174: dispatcher().assign(".*",&reply::prepare,this,0); > >And also some times ago our chinese/japanese (?) friend csfreebird posted some code like this: > > dispatcher().assign("/welcome" , &kaimei_web_site::welcome , this , 1); //first page > dispatcher().assign("/register" , &kaimei_web_site::register_client , this , 2); //register a new account on this page >.... > //restful web method called by Javascript form client-side > dispatcher().assign("/send_email" , &kaimei_web_site::save_email , this , 7); > dispatcher().assign("/create_account?(.+)" , &kaimei_web_site::create_account , this , 8); > >I think this is wrong, isn't it? > >Hope of some clearness. > >Marcel Hellwig > > > > >------------------------------------------------------------------------------ >Keep Your Developer Skills Current with LearnDevNow! >The most comprehensive online learning library for Microsoft developers >is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, >Metro Style Apps, more. Free future releases when you subscribe now! >http://p.sf.net/sfu/learndevnow-d2d >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |