DataTable - 按控制器中的客户ID限制视图

时间:2017-03-12 01:07:23

标签: php codeigniter datatables

我正在尝试修复客户端的问题。

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

在应用程序中,存在三种不同的访问级别:Admin = 1,Employee = 2,Customer = 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();
}

2 个答案:

答案 0 :(得分:2)

删除同一个表上的多个联接可能会解决您的问题。

let semaphore = DispatchSemaphore(value: 1)

for jsonObject in jsonArray {
    queue.async {
        semaphore.wait()

        print("Started downloading " + filename)
        info.stringValue = "Downloading: " + filename
        info.placeholderString = "Downloading: " + filename
        info.isEnabled = true
        info.isHidden = false
        progress.isHidden = false
        let destination: DownloadRequest.DownloadFileDestination = { _, _ in
            let documentsURL = filepath
            return (documentsURL, [.removePreviousFile])
        }
        Alamofire.download( json["url"].stringValue, method: .get, to: destination)
            .downloadProgress{ Alamoprogress in
                info.stringValue = "Downloading: " + filename
                progress.doubleValue = Alamoprogress.fractionCompleted * 100
            }
            .response { response in
                semaphore.signal()
            }
    }
}

答案 1 :(得分:1)

我已成功找到并修复了该错误。我想这是一个错误40!

我查看所有字符包括。区分大小写,并且当我从数组中获取值时,发现CustomerID应该是CustomerId。

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