0

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 which array is $name and $mail, whether $a_1 or $a_2. How do I do that?.

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

And then, how do I print them in the view? <p><?php echo $a_1->name?></p>
0

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']; ?>

1 Comment

And then, how do I print them in the view? <p><?php echo $a_1->name?></p>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.