php - How do I get this function in a controller to load in view -
this in controller
class landingpage extends ci_controller { public function startencryptedsession(){ $this->load->library('session'); $this->load->library('encrypt'); $this->load->view('index', array('session', $this->session)); } }
how load in view index
view
code
<?php echo $head; ?> <body> <?php echo $guts; ?> </body> <?php echo $foot; ?> <?php echo $session->userdata('session_key'); ?>
i'm using code igniter mvc
when load view, gives me:
<h4>a php error encountered</h4> <p>severity: notice</p> <p>message: undefined variable: session</p> <p>filename: views/index.php</p> <p>line number: 8</p> </div><br /> <b>fatal error</b>: call member function userdata() on non-object
you need pass variables want use view. this:
one way:
in controller:
public function startencryptedsession(){ $this->load->library('session'); $this->load->library('encrypt'); $data = array('session_key' => $this->session->userdata('session_key')); $this->load->view('index', $data); }
in view:
<?php echo $session_key; ?>
another way:
in controller:
public function startencryptedsession(){ $this->load->library('session'); $this->load->library('encrypt'); $data = array('session' => $this->session->all_userdata()); $this->load->view('index', $data); }
in view:
<?php echo $session['session_key']; ?>
a word of advice: codeigniter's session class kinda sucks, since stores data on cookie , has low limit of data size (or @ least how worked last time checked)... might want handle using php's default session functions or creating class of own. i'll leave check, since isn't asking.
Comments
Post a Comment