phpcodeigniterviewcontroller

How to pass data from controller to view


I need to pass data from the controller to the view. I use a loop in the controller which runs for more than 1 minute.

for ($i = 0; $i < $count; $i++) {   
    $peicedata = getdata();
    $ar = explode(",", $peicedata);
                
    $data['firstname'] = $ar[0];
    $data['lastname'] = $ar[1];
    $data['email'] = $ar[2];
    $data['website'] = $ar[3];  
}

The above function getdata() takes around 10 seconds to get data back. As data is received from getdata(), I want to pass that data immediately to the view.


Solution

  • It seems you use CodeIgniter. You can pass data to template like this:

    $this->load->view('show', $data);
    

    show is the template. And please read User Guide for more details.

    BTW, if your script runs too slow, you should check your code.