How pass parameters between controller and view Codeigniter -
my parameter array:
controller:
$data=......; $this->load->view('a/p/l',$data);
the data vector has parameter:
0 => array (size=4) 'email' => string '' (length=21) ... 1 => array (size=4) 'email' => string '' (length=21) ... 2 => array (size=4) 'email' => string '' (length=21)
anyone can show mem view can read elements in array?
here simple example
here controller named welcome.php
<?php defined('basepath') or exit('no direct script access allowed'); class welcome extends ci_controller { public function index() { $data['default'] = array( array( 'email' => 'sample@gmail.com', 'username' => 'username1' ), array( 'email' => 'sample@yahoo.com', 'username' => 'username2' ), array( 'email' => 'sample@hot.com', 'username' => 'username3' ) ); $data['title'] = 'sample'; $this->load->view('welcome_message', $data); } }
in order call pass $data array in views, make sure have reference key array like
$data['default'] = array
$data['title'] = 'sample';
in order me access data in view here sample view named
welcome_message.php
<html lang="en"> <head> </head> <body> <div id="container"> <?php foreach ($default $key => $value) { ?> <h1><?php echo $value['email'];?></h1> <?php } ?> <h6><?php echo $title;?></h6> </div> </body> </html>
to able access data pass, used reference key of pass array
default , title
and there can processing already
hope out.
Comments
Post a Comment