Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter - Set a variable in in view

Tags:

codeigniter

Can I set a variable in view file?

for exemple: I have a controller: welcome.php Its load:

$this->load->view('header');
$this->load->view('main');
$this->load->view('footer');

I need set a variable on file main.php and get on footer.php

Its possible?

like image 237
Dinho Pereira Avatar asked Jul 14 '26 23:07

Dinho Pereira


1 Answers

You can pass a variable from one view to another just like you would from a controller to a view. You just have to load the view file that sets that variable before the view that uses that variable:

$this->load->view('main'); //load before
$this->load->view('footer'); //load after

Inside of main.php do $this->load->vars(array('your_variable'=>'it's value')); and you will be able to call it in the footer like you would any other variable. The only requirement is that main.php be loaded before footer.php.

like image 188
Kevin Beal Avatar answered Jul 18 '26 08:07

Kevin Beal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!