会话用户数据类型不适用于Codeigniter中的特定功能
I use this code in home function it get the usertype and works nice.
function home()
{
$type = $this->session->userdata('type');
if($type == "admin")
{
$this->load->view('index');
}
else if($type == "QA" || "SC" || "CDC")
{
$this->load->view('aindex');
}
}
But when I use same code in jobsheet function it's not working. Code below
function jobsheet()
{
$type = $this->session->userdata('type');
$this->load->model('Ipss_model');
$var1['job'] = $this->Ipss_model->AllJobSheet();
$var2['division'] = $this->Ipss_model->AllDivision();
$var3['tItem'] = $this->Ipss_model->transactionItem();
$data = $var1 + $var2 + $var3;
if($data['job'] != NULL )
{
if($type == "SC" || "CDC")
{
$this->load->view('jobsheet',$data);
}
else if($type == "admin" || "QA" )
{
$this->load->view('jobsheetQA',$data);
}
}
else
{
$this->load->view('jobsheetEmpty',$data);
}
}
Please help me about this. Thanks in advance.
我在home函数中使用此代码,它获得了usertype并且效果很好。 p>
但是当我在工作表函数中使用相同的代码时,它不起作用 。 代码 p>
请帮我解决这个问题。 提前致谢。 p>
div> function home()
{
$ type = $ this-> session-> userdata('type');
if($ type ==“admin”)
{
$ this-> load-> view('index');
}
if if($ type ==“QA”||“SC”||“CDC”)
{
$ this-> load-> view('aindex');
}
}
code> pre>
function jobsheet()
{
$ type = $ this-> session-> userdata('type');
$ this-&gt ; load-> model('Ipss_model');
$ var1 ['job'] = $ this-> Ipss_model-> AllJobSheet();
$ var2 ['division'] = $ this- > Ipss_model-> AllDivision();
$ var3 ['tItem'] = $ this-> Ipss_model-> transactionItem();
$ data = $ var1 + $ var2 + $ var3; \ n
if($ data ['job']!= NULL)
{
if if($ type ==“SC”||“CDC”)
{
$ this-> load-> view('jobsheet',$ data);
}
if if($ type ==“admin”||“QA”)
{
$ this-> load-> view('jobsheetQA' ,$ data);
}
}
其他
{
$ this-> load-> view('jobsheetEmpty',$ data);
}
}
code> pre>
To check weather array is empty or not you can use empty(). Also change your ||
condition like below.
So you condition would be
if(!empty($data))
{
if($type == "SC" || $type =="CDC")
{
$this->load->view('jobsheet',$data);
}
else if($type == "admin" || $type == "QA" )
{
$this->load->view('jobsheetQA',$data);
}
}
check your array() before using it in if condition with -:
echo "<pre>"; print_r($data); die();