This is in a 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 do I load this in the 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 I load the view, it gives me:
<h4>A PHP Error was 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 to a member function userdata() on a non-object
You need to pass the variables you want to use to your view.
Something like this:
One way:
In your controller:
In your view:
Another way:
In your controller:
In your view:
A word of advice: CodeIgniter’s session class kinda sucks, since it stores data on a cookie and has a very low limit of data size (or at least that was how it worked last time I checked)… so you might want to handle it using PHP’s default session functions or creating a class of your own. But I’ll leave that for you to check, since it isn’t what you were asking.