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

ページ上の 2 つのボタンをクリックすると、変数が影響を受けますroute.info.num[0/1].value()。それらを使用してグローバル変数を変更しますnum_active。この変数は文字列に変換され、ページ (ビュー) に表示されます。

ただし、次の行がある場合にのみ機能します。

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

下に配置。上に配置すると、適切にレンダリングされnum_activeません (または、正しい値がありませんか?)。なぜこれが起こっているのか誰か教えてもらえますか?これは私にとってとにかく論理的ではありません。

4

0 に答える 0