Welcome Guest, Not a member yet? Register   Sign In
passing arguments to view
#1

[eluser]PankajBalani[/eluser]
can i pass $this->load->view('mainView',$data1,$data2) instead of $this->load->view('mainView',$data) where $data['1']=1 and $data['2']=2;
#2

[eluser]Samus[/eluser]
No.

$data is an array, pass additional information to it.

Code:
$data['one'] = 1;
$data['two'] = 2;

$this->load->view('mainView', $data);
#3

[eluser]Nakul Khandelwal[/eluser]
This works:
Code:
$data['one'] = 1;
$data2['two'] = 2;

$this->load->view('mainView', $data);
$this->load->view('secondView', $data2);

But this does not:
Code:
$data['one'] = 1;
$data2['two'] = 2;

$this->load->view('mainView', $data, $data2);

Right now I am using <a href="http://php.net/manual/en/function.array-merge.php">array_merge</a> for the data array. But this includes a lot of unnecessary code in the controller as well as in the view when I have two big arrays to pass.

Is there a way to pass two arrays to a single view?


#4

[eluser]pbflash[/eluser]
The load->view function only allows for 1 array to be passed (see the user guide). The third parameter is used for a true/false value to tell the function to either return the output to the function or the browser.

You could extend the loader class and create your own view function.
#5

[eluser]Nakul Khandelwal[/eluser]
[quote author="pbflash" date="1337211777"]The load->view function only allows for 1 array to be passed (see the user guide). The third parameter is used for a true/false value to tell the function to either return the output to the function or the browser.

You could extend the loader class and create your own view function. [/quote]

Thanks. This makes everything clear.
#6

[eluser]kptengco[/eluser]
try this one if fits for you

Code:
$this->hcontent['title'] = 'Z FIMS - Flight Destinations';
$this->hcontent['script'] = 'headers/fl_destination';

$this->bcontent['greeting'] = $this->fimslib->__greetings().$user_fullname;
$this->bcontent['logout'] = $user_access.':'.$user_fullname;
$this->bcontent['query'] = $result;

$data['header_content'] = $this->hcontent;
$data['body_content'] = $this->bcontent;

//$data['header'] = 'header';
//$data['body'] = 'pages/fl_destination';
//$data['footer'] ='footer';

$this->load->view('master',$data);
#7

[eluser]Samus[/eluser]
[quote author="Nakul Khandelwal" date="1337211115"]This works:
Is there a way to pass two arrays to a single view?
[/quote]
Code:
$data['one'] = array(1, 11);
$data['two'] = array(2, 22);

$this->load->view('mainView', $data);

You now have 2 arrays.

in your view it'd be something like this:

Code:
&lt;?php echc $one[0]; ?&gt; // echo's 1.
&lt;?php echo $two[1]; ?&gt; // echo's 22.

etc
#8

[eluser]Aken[/eluser]
What is the purpose of your two arrays of data? You mention unnecessary code - tell us about your situation if you want a better recommendation.




Theme © iAndrew 2016 - Forum software by © MyBB