Main  /  Edit version 3  /  Edit version 4  /   /  Users Area

Difference "cppcms::url_parser" ver. 3 versus ver. 4


This content is down.
## Role
This class is used for spawning requests according given URL by matching them by regular expressions.
It is defined in `cppcms/url.h` header.
## Constructor
url_parser(worker_thread *w);
Creates new URL parser. First version creates standalone parser that can be used for any input string. Second derives the string from CGI variable `PATH_INFO`.
## General Recommendations
Always use callbacks to setup your url dispatching functions.
## Public Member Functions
### Setting Handlers
#### Binding to callback
void add(char const *expr,callbac_t );
Binds expression to callback. `callback_t` is boost::function with 9 string parameters where:
- First 8 parameters are matched expressions --- $1,..,$8
in "perl" semantics.
- Last 9 parameter is entry expression -- $0 in "perl" semantics.
For example:
class app : public application {
void page(string id);
app(...) ...
Would setup callback to `page` member function and pass string id with matched number.
In versions prior to CppCMS 0.0.4, you could use macros $0, $1, ... $8 that were defined in `url.h` header. They are
depricated and should not be used becuase `$` in identifiers
is not supported on some platforms like ARM.
#### Binding to ID
void add(char const *exp,int id);
Causes `url_parser::parse` return `id` when match had found.
#### Binding to other url\_parser:
void add(char const *exp,url_parser &url);
Forces `url_parser` to pass string to other parser if match was found. It may be used for faster matching urls. For example:
### Parsing URL
int parse();
int parse(string &s);
Parses URL using `s` or `PATH_INFO`. It returns
- `url_parser::ok` if callback was dispatched
- `url_parser::not_found` if no match was found.
- Other positive number if URL was associated with number and not callback.
If you using `url_parser` that returns id, you can find matched parameters using operator `[]`. For example:
switch(url.parse()) {
case 1: id=url[1];


This content is down.
## Related
- [cppcms::application](/wikipp/en/page/ref_cppcms_base_view)


CppCMS is a web development framework for performance demanding applications.

Support This Project Logo

Поддержать проект

CppCMS needs You


Main Page

Valid CSS | Valid XHTML 1.0