CodeIgniter Forums
$this->load->vars() in CI4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: $this->load->vars() in CI4 (/showthread.php?tid=80215)



$this->load->vars() in CI4 - objecttothis - 09-30-2021

I'm trying to convert an existing CI3.x application to CI4.x At the end of one of my controllers I am calling

PHP Code:
        $data['user_info'] = $logged_in_employee_info;
        
$data['controller_name'] = $module_id;

        
$this->load->vars($data); 

It's probably really obvious and I'm just missing it, but how do I need to convert $this->load->vars(); for use with CI4? I can't seem to find any documentation about it.

I looked here: https://codeigniter4.github.io/CodeIgniter4/installation/upgrading.html and while that is extensive, there doesn't seem to be a master conversion table showing which functions go to what CI4 counterparts. I searched this forum and found someone complaining that CI4 doesn't have $this->load->vars() but didn't seem to find a clear alternative.


RE: $this->load->vars() in CI4 - kilishan - 09-30-2021

I believe the point of $this->load->vars() was to make it available to the views. No you can add data directly when you call the view() function.

PHP Code:
$data['user_info'] = $logged_in_employee_info;
$data['controller_name'] = $module_id;

echo 
view('dashboard'$data); 



RE: $this->load->vars() in CI4 - iRedds - 09-30-2021

(09-30-2021, 06:17 AM)kilishan Wrote: I believe the point of $this->load->vars() was to make it available to the views. No you can add data directly when you call the view() function.

PHP Code:
$data['user_info'] = $logged_in_employee_info;
$data['controller_name'] = $module_id;

echo 
view('dashboard'$data); 
I think TS is talking about preloading the shared data for use in the template.

Not sure, but it seems to me that the solution is View::setData() and View::setVar() methods


RE: $this->load->vars() in CI4 - InsiteFX - 10-01-2021

The way I made it work in CI4 was to have a seperate view just for the data works fine.


This makes the variables avaible to all the views, create a blank view viewData.php and call it as the first view.

PHP Code:
echo view('viewData'$data);
echo 
view('viewMain'); 

Try that.