Welcome Guest, Not a member yet? Register   Sign In
$this->load->vars() in CI4
#1

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/CodeIgnit...ading.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.
Reply
#2

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); 
Reply
#3

(This post was last modified: 09-30-2021, 09:15 AM by iRedds.)

(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
Reply
#4

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB