开发者

Check session from a view in CodeIgniter

开发者 https://www.devze.com 2022-12-11 04:56 出处:网络
What is the best way to check session from a view in CodeIgniter, it shows n开发者_高级运维o way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...stil

What is the best way to check session from a view in CodeIgniter, it shows n开发者_高级运维o way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to CodeIgniter...

Please Help! Thanks...


Load it into the view like any other piece of data...

$data['item'] = $this->session->userdata('item');
$this->load->view('view', $data);


In view, you can access all loaded library, model, and helper function directly. If in controller you have load the session, or do it in autoload, then doing this in views will work:

<?php echo $this->session->userdata('session_key'); ?>

If you want to access some function that haven't loaded in autoload or in the controller, you can use this:

<?php
$CI =& get_instance();
$CI->load->model('some_model');
echo $CI->some_model->some_function($some_param);
?>

I usually use this for a common view that loaded by other views, such as displaying visitor country flag, etc.

Hope this help.

0

精彩评论

暂无评论...
验证码 换一张
取 消