public function LoginUser()
{
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('login');
}
else
{
$data['Email']=$this->input->post('email');
$data['Password']=$this->input->post('password');
$result=$this->UserAccount_model->LoginUser($data);
if($result)
{
$session_data = array(
'sesid' => $result[0]->id,
'sesname' => $result[0]->Name,
'sesemail' => $result[0]->Email);
// Add user data in session
$this->session->set_userdata('logged_in', $session_data);
$url=base_url()."UserAccount/LoggedIn";
header("Location:$url");
}
现在我正在访问照片控制器中的会话数据
public function LikePhoto()
{
$Id=$this->uri->segment(3);
$UserId=$this->$session_data['sesid'];
print($UserId);
exit();
但这会产生错误
遇到PHP错误
严重性:注意
消息:未定义的变量:session_data
文件名:controllers / Photo.php
行号:55
答案 0 :(得分:2)
在CI中获取会话数据,您必须使用$UserId=$this->session->userdata('logged_in')['sesid'];
所以将代码更改为:
$this->session->set_userdata('logged_in', $session_data);
编辑如果要存储数据中的数据,只需在会话中添加数组变量
所以改变
$this->session->set_userdata($session_data);
要
$UserId=$this->session->userdata('sesid');
并检索:
Excel.Application xlAppToExport = new Excel.Application();
xlAppToExport.Workbooks.Add("");
Excel.Worksheet xlWorkSheetToExport = default(Excel.Worksheet);
xlWorkSheetToExport = (Excel.Worksheet)xlAppToExport.Sheets["Sheet1"];
xlWorkSheetToExport.Range["A5:F5"].EntireRow.Interior.Color = System.Drawing.Color.Gray;