Welcome Guest, Not a member yet? Register   Sign In
How can i echo variable of one view page to another view page ?
#1

[eluser]dhaulagiri[/eluser]
How can i echo variable of one view page to another view page of same controller and different controller ?

do i need to use php include ?
#2

[eluser]LuckyFella73[/eluser]
It depends what you want to achieve axactly. If your variable never
changes you could DEFINE it and use where ever you want.

For controller-wide usage you can code somthing like the following
in yout controller constructor:
Code:
$this->my_var = "example value";

and send to the views called by your controller
Code:
// method 1:
$data['my_var'] = $this->my_var;
$this->load->view('view_example', $data);

// method 2:
$data['my_var'] = $this->my_var;
$this->load->view('view_another_example', $data);
#3

[eluser]rufnex[/eluser]
If you have a nested view like that:

main.php:
Code:
<html>
...
   <?php echo $this->load->view('nav', $data); ?>
   <?php echo $name; ?>
</html>

nav.php:
Code:
<?php echo $title; ?>

You can route the data vars with somethink like that in your controller:

xyz_controller.php:
Code:
$data['title'] = "My Title";
$data['name'] = "My_Name";
$data['data'] = $data;    
$this->load->view('main.php', $data);

Anyone has a better idea or solution for that?




Theme © iAndrew 2016 - Forum software by © MyBB