J. Doe
J. Doe

Reputation: 431

CppCMS - controller / view code does not work right

I have the following CppCMS MVC code:

void routing_controller()
{
    this->route.username = "My name";
    //this->route.debug_string = to_string(num_active);     // won't work here

    if(request().request_method() == "POST")
    {
        this->route.info.load(context());
        if(this->route.info.validate())
        {
            if(this->route.info.num[0].value() == true)
            {
                this->num_active = 0;
            }
            else if(this->route.info.num[1].value() == true)
            {
                this->num_active = 1;
            }
        }
        this->route.debug_string = to_string(num_active);       // only works here
    }
    render("route", this->route);
}

Clicking two buttons on the page affect the variables route.info.num[0/1].value(). I use them to change the global variable num_active. This variable is converted to a string and display on the page (view).

However, it only works if I have the line:

this->route.debug_string = to_string(num_active);

placed below. If I place it above, it will not render properly (or num_active does not have the right value?). Could someone tells me why this is happening? This is not logical anyhow to me.

Upvotes: 0

Views: 48

Answers (0)

Related Questions