[Cppcms-users] How to avoid "Access to unassigned context"
Brought to you by:
artyom-beilis
|
From: Marcel H. <ke...@co...> - 2011-12-15 08:08:25
|
Good morning,
I'm writing a program that uses sessions. Here's my config:
"session" : {
"location" : "server",
"timeout" : 3600, //1 hour
"expire" : "renew",
"cookies" : {
// "domain" : "localhost",
"path" : "/",
"prefix" : "bg_",
"secure" : false,
},
"server" : {
"storage" : "files",
"dir" : "tmp/cookies",
"shared" : false,
},
"gc" : 86400 //once a day
},
now my problem.
I'm using the dispatcher, there I assign the "fill" method, named
prepare. Everything works until now. In this "fill" method i declare a
new pointer to an Object and give this pointer to an other method, named
"fillContent". There i use some methods from the "pointed-Object". In
that object I have to, or I want to the session. That for the
Constructor of the Object becomes the cppcms::application reference.
Now I try to set, or to read a cookie. Both fails with the error "Access
to unassigned context". If i remove that "session-line" everything works
back to normal.
Please, give me some advices.
Regards,
Marcel Hellwig
Hamburg, Germany
Here some code:
Dispatcher::Dispatcher(cppcms::service &s) : cppcms::application(s) {
.....
attach(new Techtree(s),
"Techtree",
"/techtree/{1}",
"/techtree/?(.*)", 1);
.....
}
Techtree::Techtree(cppcms::service& srv) : BasePage(srv) {
mapper().assign("{1}");
mapper().assign("");
dispatcher().assign(".*", &Techtree::prepare, this, 0);
}
void Techtree::prepare(std::string /*page*/) {
User* user;
......
user = new User(_srv, session().get<int>("uID"));
......
session().set("uID", "1"); //this works!
.....
fillContent(c, user); //c is the struct of template strings
delete user;
}
void Techtree::fillContent(data::techtree::main c, User* user) {
c.MetalMineDep = "<tr><td>---</td></tr>";
user->getBuildingLevel(101, 1);
c.SolarPowerPlantDep = "<tr><td>---</td></tr>";
render("techtree", c);
}
User::User(cppcms::service& srv, int id) : cppcms::application(srv),
_srv(srv), _userID(id) {
_conn_str = _srv.settings().get<std::string>("bg.connection_string");
_sql.open(_conn_str);
_init();
}
void User::_init() {
........
session().set("test, "test123"); //here the error occurs
}
|