【问题标题】:How to load view and return value to another function in controller codeigniter如何在控制器codeigniter中加载视图并将值返回到另一个函数
【发布时间】:2016-06-18 16:41:28
【问题描述】:

我是codeigniter的新手,我需要加载一个视图并将值返回给另一个控制器。如何制作它

这是我的控制器

function test1 {


  $value=  $this->input->post('value1');
  //some code 
   return ($result)
  $this->load->view('test');

}

function test2 {


  $resultvalue= $this->test1;

   echo($result);
          //some code 


}

【问题讨论】:

    标签: php codeigniter controller views codeigniter-3


    【解决方案1】:

    遵循此代码。

    function test1() {
     $value=  $this->input->post('value1');
     //some code 
     $data =$this->load->view('test','',TRUE);
     return ($data)
     }
    
     function test2 {
        $resultvalue= $this->test1;
        echo resultvalue;
          //some code 
    
    }
    

    您需要在加载视图时将第三个参数设置为 TRUE 以获取视图的数据(HTML)。 希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      你可以使用这些方法

      1. Codeigniter Session
      2. Codeigniter Cookie
      3. Codeigniter Global variable

      作为您的问题,我建议您使用 Session.

      添加会话

      $this->session->set_userdata('result', $result);
      

      检索会话

      $this->session->userdata('item');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-10-01
        • 2013-12-06
        • 2012-12-19
        • 1970-01-01
        • 2012-03-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多