Welcome Guest, Not a member yet? Register   Sign In
View in side another view with same parameters
#1

[eluser]Nisha S.[/eluser]
I want to load a common sub view inside many other views but by passing the same data which is passed to the main view. Please let me know how I can achieve this.

Thank you.
#2

[eluser]Sanjay Sarvaiya[/eluser]
Please read a thread http://ellislab.com/forums/viewthread/65586/
#3

[eluser]Samus[/eluser]
[quote author="Nisha S." date="1339479791"]I want to load a common sub view inside many other views but by passing the same data which is passed to the main view. Please let me know how I can achieve this.

Thank you.[/quote]
You don't have to do anything, the data you pass to one view gets 'inherited' in other views loaded by that parent view.

e.g

Code:
$data['test'] = 'testing this';
$data['test2'] = 'testing this 2';
$this->load->view('parent', $data);

then in parent

Code:
$this->load->view('child');
echo $test; // will echo 'testing this'

Code:
$this->load->view('grandchild');
echo $test; // will echo 'testing this'
echo $test2; // will echo 'testing this 2'
#4

[eluser]Nisha S.[/eluser]
Thank you Samus. I was thinking in a too complex way..
#5

[eluser]CroNiX[/eluser]
You can also use load::vars($array) to make variables available globally, and then you don't have to explicitly pass them to a view; they will just be available.

Code:
$data['page_title'] = 'my title';
$data['h1'] = 'my h1';
$this->load->vars($data);  //make vars available to all views

$this->load->view('header');  //Don't need to pass $data
//In header.php;
echo $page_title;

$this->load->view('content');  //Don't need to pass $data
//In content.php
echo $h1;




Theme © iAndrew 2016 - Forum software by © MyBB