gpt4 book ai didi

php - DataTable - 通过 Controller 中的客户 ID 限制 View

转载 作者:可可西里 更新时间:2023-11-01 01:14:34 24 4
gpt4 key购买 nike

我正在尝试解决客户的问题。

他有一个在 Codeigniter 框架上运行的应用程序。在此应用中,他正在通过 DataTables 查看作业列表。

在应用程序中,存在三种不同的访问级别:Admin = 1、Employee = 2、Customer = 3

我试图限制分配列表,只显示属于单个客户的分配。我已尝试在 Controller 中为分配列表添加功能,但它对我不起作用。

我做错了什么?

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();
}

关于php - DataTable - 通过 Controller 中的客户 ID 限制 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42742547/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com