我有一个用户的名字和姓氏存储在会话数据中,我想在视图中回显它,这样他们就可以看到他们以谁的身份登录。我似乎无法让数据通过。我确信这很容易,但我对 CI 和整个 MVC 的东西还是很陌生。
控制器代码:
public function index() {
if($this->session->userdata('admin_signed_in')){
$this->load->model('dashboard_model');
$data['userdata'] = $this->session->userdata;
$data['main_content'] = 'dashboard/dashboard';
$this->load->view('common/template', $data);
} else {
redirect('signin');
}
}
查看代码:
<?php echo $userdata('first_name') ?> <?php echo $userdata('last_name') ?>
打印 R 结果:
Array ( [session_id] => 69db0f9ccbfde96d92cc09837067438c [ip_address] => ::1 [user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0 [last_activity] => 1352998508 [user_data] => [0] => Array ( [admin_id] => 10 [first_name] => Richard [last_name] => Coy [admin_role] => 1 ) [admin_signed_in] => 1 )