我有下面的代码
public fucntion __construct(){
parent::__construct();
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['staff_no'] = $session_data['staff_no'];
$data['staff_email'] = $session_data['staff_email'];
$data['staff_fname'] = $session_data['staff_fname'];
$data['staff_lname'] = $session_data['staff_lname'];
$data['staff_level'] = $session_data['staff_level'];
}
else
{
redirect('login','refresh');
}
现在,我有另一个功能
public function index()
{
$staff_no=$this->staff_no;
$this->load->view('header');
$this->load->view('accounts/left-nav');
$this->load->view('accounts/top-nav');
$this->load->view('accounts/home');
$this->load->view('footer',$staff_no);
}
上面的$ staff_no 变量是为了获取 $ data [' staff_no'] = $ session_data [&# 39; staff_no']; 位于__construct函数中,但将错误视为未定义变量 staff_no 请帮助
答案 0 :(得分:1)
您尚未定义$this->staff_no
,您已在构造函数中设置了局部变量$data['staff_no']
。
如果要在类的其他方法中访问变量,则需要将其存储在属性中:
构造
$this->staff_no = $session_data['staff_no'];