我正在尝试解决客户端的问题.
他有一个在Codeigniter框架上运行的应用程序.
在此应用程序中,他正在通过DataTables查看分配列表.
在该应用程序中,存在三种不同的访问级别:管理员= 1,员工= 2,客户= 3
我试图限制分配列表,以仅显示属于单个客户的分配.我试图在控制器中为分配列表添加功能,但对我而言不起作用.
我究竟做错了什么?
public function assignlist( $status = "" ){
$status1 = "Aktiv";
if($status!=""){
$status1 = $status;
}
/* by Kenn */
$log_in = $this->session->userdata('logged_in');
$roleid = $log_in["role_id"];
$CustomerID = $log_in["CustomerID"];
/**/
$this->datatables->select('er.EventId,er.EventName,cu.CustomerName as CustomerId,DATE_FORMAT(er.EventDate, "%d/%m/%Y") AS EventDate,er.TimeFrom,er.TimeTo,er.NoofGuardRequired,er.Remarks,emp.fullname as InsertBy,emp1.fullname as ModifiedBy,er.Status,er.Status as st,cu12.CustomerName as cuInsertBy, cu1.CustomerName as cuModifiedBy');
$this->datatables->from('eventregistration er');
$this->datatables->join('customer cu', 'cu.CustomerId = er.CustomerId', 'left');
$this->datatables->join('employee emp', 'emp.emp_id = er.InsertBy', 'left');
$this->datatables->join('employee emp1', 'emp1.emp_id = er.ModifiedBy', 'left');
$this->datatables->join('customer cu12', 'cu12.CustomerId = er.InsertBy', 'left');
$this->datatables->join('customer cu1', 'cu1.CustomerId = er.ModifiedBy', 'left');
$this->datatables->where('er.Status',$status1);
/* by Kenn */
if ($roleid == "3"){
$this->datatables->where('cu.CustomerID',$CustomerID);
}
/**/
echo $this->datatables->generate();
}
解决方法:
删除同一表上的多个联接可能会解决您的问题.
public function assignlist( $status = "" ){
$status1 = "Aktiv";
if($status!=""){
$status1 = $status;
}
/* by Kenn */
$log_in = $this->session->userdata('logged_in');
$roleid = $log_in["role_id"];
$CustomerID = $log_in["CustomerID"];
/**/
$this->datatables->select('er.EventId,er.EventName,cu.CustomerName as CustomerId,DATE_FORMAT(er.EventDate, "%d/%m/%Y") AS EventDate,er.TimeFrom,er.TimeTo,er.NoofGuardRequired,er.Remarks,emp.fullname as InsertBy,emp.fullname as ModifiedBy,er.Status,er.Status as st,cu.CustomerName as cuInsertBy, cu.CustomerName as cuModifiedBy');
$this->datatables->from('eventregistration er');
$this->datatables->join('customer cu', 'cu.CustomerId = er.CustomerId AND cu.CustomerId = er.InsertBy AND cu.CustomerId = er.ModifiedBy', 'left');
$this->datatables->join('employee emp', 'emp.emp_id = er.InsertBy AND emp.emp_id = er.ModifiedBy', 'left');
$this->datatables->where('er.Status',$status1);
/* by Kenn */
if ($roleid == "3"){
$this->datatables->where('cu.CustomerID',$CustomerID);
}
/**/
echo $this->datatables->generate();
}