0

我有以下 CppCMS MVC 代码:

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);
}

单击页面上的两个按钮会影响变量route.info.num[0/1].value()。我用它们来改变全局变量num_active。该变量被转换为字符串并显示在页面(视图)上。

但是,它只有在我有这条线时才有效:

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

置于下方。如果我把它放在上面,它不会正确渲染(或者num_active没有正确的值?)。有人可以告诉我为什么会这样吗?这对我来说无论如何都不合逻辑。

4

0 回答 0