开发者

is there a better, more lightweight way to access session data in codeigniter view?

开发者 https://www.devze.com 2023-01-06 22:39 出处:网络
Is there a more lig开发者_如何学编程htweight way to access session data in a view with codeigniter than posted here?

Is there a more lig开发者_如何学编程htweight way to access session data in a view with codeigniter than posted here?

i think about soemthing like {session.myparameter}.

thanks for help


Assign your session data to an array in your controller that pass it to the view with the rest of the page data.

$page_data['session_data']  = array(
    'session_param_1' => $this->session->userdata('session_param_1'),
    'session_param_2' => $this->session->userdata('session_param_4'),
    'session_param_3' => $this->session->userdata('session_param_3'),
    'session_param_4' => $this->session->userdata('session_param_2')
);

$this->load->view('your_view', $page_data);

To access the session class directly from a view you must ensure that the session library has been loaded by the calling controller, or has been autoloaded in application/config/autoload.php

$autoload['libraries'] = array('database', 'session');

Then access in your view as required.

<h2>Logged in as <?php echo $this->session->userdata('session_user_name'); ?> </h2>
0

精彩评论

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