2013-10-08 38 views
2

我在使用URL映射的cppcms hello world example遇到问题。cppcms - 为什么你的世界与URL映射不工作?

我有理解这一部分的麻烦:

int main(int argc,char ** argv) 
{ 
    try { 
     cppcms::service srv(argc,argv); 


     srv.applications_pool().mount(
       cppcms::applications_factory<hello>() //i do not understand this part 
     ); 

     srv.run(); 
    } 
    catch(std::exception const &e) { 
     std::cerr << e.what() << std::endl; 
    } 
} 

在教程中称/你好 - 欢迎功能将被称为但这不是发生了什么。 这种方法被称为替代:

void hello::main(std::string /*url*/) 
{ 
    response().out() << 
     "<html>\n" 
     "<body>\n" 
     " <h1>Hello World</h1>\n" 
     "</body>\n" 
     "</html>\n"; 
} 

欢迎方法这个样子的,它是在Hello类的范围定义为:

void welcome() 
{ 
    response().out() << 
     "<h1> Welcome To Page with links </h1>\n" 
     "<a href='" << url("/number",1) << "'>1</a><br>\n" 
     "<a href='" << url("/number",15) << "'>15</a><br>\n" 
     "<a href='" << url("/smile") << "' >:-)</a><br>\n"; 
} 

我需要找到一些答案,如果你能帮助我。我只是想明白,所以如果你能指向正确的方向,那将会很棒。

+0

它是行不通的,或者你不明白*它是如何工作的? – crashmstr

+0

我不明白它是如何工作的。你知道关于cppcms的一些很好的文档。 – pregmatch

回答

3

您需要在hello构造函数中设置映射,如hello world示例和您在答案中发布的链接所示。

特别是,该部分:

dispatcher().assign("",&hello::welcome,this); 
mapper().assign(""); 

mapper().root("/hello"); 

此Hello应用程序的默认路由映射到了“欢迎”的方法。如果你没有设置映射,它将默认为main。

0

我个人不很了解这个库,但它看起来像行:

cppcms::applications_factory<hello>() 

你assosating与服务器,并instantaiteing某种hello类的。然而我