@rollin
To pass an array to the main view in CodeIgniter, you can use the second parameter of the load->view()
method.
1 2 3 4 5 |
$data = array( 'name' => 'John Doe', 'age' => 30, 'country' => 'USA' ); |
1
|
$this->load->view('main_view', $data); |
Here, main_view
is the name of your view file.
1 2 3 |
<p>Name: <?php echo $name; ?></p> <p>Age: <?php echo $age; ?></p> <p>Country: <?php echo $country; ?></p> |
Here, you can simply access the array values using the corresponding keys ('$name', '$age', and '$country').
Note: Make sure you have already loaded the 'view' library in your controller, either in the constructor or using the $this->load->library('view')
method.