Reputation: 105
I'm trying to pass two arrays ($a_1 and $a_2) from my controller to my view like so:
$this->load->view('confirm_data_v', $a_1, $a_2);
In my view I want to print the value of one of them doing this:
<p><?php echo $name ?></p>
<p><?php echo $mail ?></p>
when I print each array I get this:
Array
(
[name] => jon
)
Array
(
[mail] => [email protected]
)
$name is a field inside $a_1 and $mail is a field inside $a_2, but it seems like the view doesn't know where these fields are, I mean, it doesn't know in wich array is $name and $mail, wether $a_1 or $a_2. How do I do that?.
Upvotes: 0
Views: 2507
Reputation: 1703
the codeigniter wiki sais this
$data = array(
'name' => $a_1['name'],
'mail' => $a_2['mail'],
);
$this->load->view('confirm_data_v', $data);
https://www.codeigniter.com/user_guide/general/views.html
Upvotes: 1
Reputation: 7491
You're passing the arrays in an incorrect way. You can only pass one data array as a second parameter while loading the view.
You could instead put each array in the data array in your controller:
$data['a_1'] = $a_1;
$data['a_2'] = $a_2;
$this->load->view('confirm_data_v', $data);
Then in your view you can access $a_1 and $a_2 as you like
Name: <?php echo $a_1['name']; ?>
Email: <?php echo $a_2['mail']; ?>
Upvotes: 0