【问题标题】:Load additional data into the view将其他数据加载到视图中
【发布时间】:2015-10-25 23:53:44
【问题描述】:

我有这个 PHP 代码,我在其中将测验加载到视图中。当我选择并提交答案时,视图会发生变化,只显示正确的消息或错误的消息。 我想要实现的是在单击答案的提交按钮时,保留问题并在正确与否的情况下显示。 这是我的代码:

function guess()
{
    $guess = $this->input->get('name',false);
    $personid = $this->input->get('id',false);
    if ($guess === null) {

        $newguess['data'] = $this->Starmodel->getQuestion();
        $this->load->view('starview',$newguess);
    }
    else {
        $res= $this->Starmodel->isCorrectAnswer($personid,$guess);
        $person = $this->load->view('starview', array('iscorrect' => $res,
                                                      'name' => $guess));
         }     
}

我的主要视图是starview.php。我可以使用 div 并以特定 div 内的特定加载视图为目标吗?我该怎么做?

谢谢

【问题讨论】:

    标签: php codeigniter model-view-controller


    【解决方案1】:

    让我们这样说你的startview视图...

    //Your question goes here
    
    
    
    //Answer part
    <?php if($this->input->post()): 
          echo $answer_view_data 
     endif; ?>
    

    在你的function guess()

    function guess()
    {
        $guess = $this->input->get('name',false);
        $personid = $this->input->get('id',false);
        if ($guess === null) {
    
            $newguess['data'] = $this->Starmodel->getQuestion();
            $this->load->view('starview',$newguess);
        }
        else {
            $res= $this->Starmodel->isCorrectAnswer($personid,$guess);
            $answer_data = 'Sample answer data';
            $person = $this->load->view('starview', array('iscorrect' => $res,
                                                          'name' => $guess, 'answer_data' => $answer_data));
             }     
    }
    

    【讨论】:

    • 数据显示方式相同。我已经在显示答案 'name' => $guess
    猜你喜欢
    • 2013-05-28
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    相关资源
    最近更新 更多