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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With