我正在使用Codeigniter3,我有一个GridView文件,我放在Library文件夹中。
这是我的GridView代码;
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
class GridView{
private $data;
private $headers;
private $is_sortable;
private $sort_columns;
private $current_sort;
private $show_checkbox;
private $per_page;
private $total_items;
private $current_page;
private $column_count;
private $pagination_dots_threshold;
private $search_url;
private $deleteOption;
private $formAction;
private $formID;
function __construct(){}
public function init($config=array()){
$default=array(
"id"=>"companies",
"css_table_classes"=>"table table-bordered table-striped table-hover",
"data"=>array(),
"headers"=>array(),
"is_sortable"=>true,
"sort_columns"=>array(),
"current_sort"=>"",
"show_checkbox"=>true,
"per_page"=>20,
"total_items"=>42,
"current_page"=>1,
"pagination_dots_threshold"=>20,
"search_url"=>false,
"deleteOption"=>true,
"formAction"=>"",
"formID"=>""
);
$final= $config + $default;
foreach($final as $k=>$v){
$this->{$k}=$v;
}
$positive = $negative = $this->negative_sort_columns=array();
if(is_array($this->sort_columns) && count($this->sort_columns) > 0){
foreach ($this->sort_columns as $col) {
if(stripos($col,'!')!==false){
$negative[]=str_replace("!","",$col);
}else{
$positive[]=$col;
}
}
$this->sort_columns=$positive;
$this->negative_sort_columns=$negative;
}
}
}
我在我的控制器中调用它,就像这样,
$grid=load_class("GridView", $directory = 'libraries', $prefix = '');
但是它显示了一个错误,并说 Class&#39; CI_GridView&#39;在第195行的C:\ xampp \ htdocs \ mgt \ Master_Panel \ system \ core \ Common.php中找不到
请帮我解决这个问题
答案 0 :(得分:1)
您可以使用load_class()
代替$this->gridview->init($config);
。
并将其功能称为:load_class()
或者,如果您真的想使用$grid=load_class("GridView", 'libraries', '');
,则必须重命名您的类MY_GridView并将其保存为同名文件 - MY_GridView.php。并按照您的方式将其加载到控制器中 - {{1}}