Menu

[r613]: / framework / trunk / hello_world.cpp  Maximize  Restore  History

Download this file

89 lines (80 with data), 1.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "application.h"
#include "manager.h"
#include "hello_world_view.h"
using namespace cppcms;
class my_hello_world : public application {
public:
my_hello_world(worker_thread &w) :
application(w)
{
url.add("^/?$",
boost::bind(&my_hello_world::std,this));
url.add("^/test?$",boost::bind(&my_hello_world::test,this));
use_template("view2");
};
void test();
void std();
};
void my_hello_world::test()
{
if(!session.is_set("time")) {
cout<<"No Time\n";
}
else {
time_t given=session.get<time_t>("time");
cout<<asctime(gmtime(&given))<<"<br/>\n";
if(session.is_set("msg")) {
cout<<session["msg"]<<"<br/>";
}
if(given % 3 == 0) {
cout<<"SET LONG MESSAGE";
session["msg"]="Looooooooooooooooooooooooooooooong msg";
}
else {
cout<<"UNSET LONG MESSAGE";
session.del("msg");
}
cout<<"<br/>"<<endl;
if(session.is_set("msg")) {
int val=given % 2;
session.expose("msg",val);
cout<<(val ? "exposed" : "hidden")<<endl;
}
//session.clear();
}
session.set<time_t>("time",time(NULL));
}
void my_hello_world::std()
{
view::hello v(this);
if(env->getRequestMethod()=="POST") {
v.form.load(*cgi);
if(v.form.validate()) {
session["name"]=v.form.username.get();
v.username=v.form.username.get();
v.realname=v.form.name.get();
v.ok=v.form.ok.get();
v.password=v.form.p1.get();
v.form.clear();
}
}
v.title="Cool";
if(session.is_set("name"))
v.title+=":"+session["name"];
v.msg=gettext("Hello World");
for(int i=0;i<15;i++)
v.numbers.push_back(i);
v.lst.push_back(view::data("Hello",10));
render("hello",v);
}
int main(int argc,char ** argv)
{
try {
manager app(argc,argv);
app.set_worker(new application_factory<my_hello_world>());
app.execute();
}
catch(std::exception const &e) {
cerr<<e.what()<<endl;
}
}
MongoDB Logo MongoDB