Мой класс таблицы данных:
Код: Выделить всё
class Datatables extends CI_Model {
protected $columnOrder;
protected $columnSearch;
protected $query;
public function __construct($columnOrder,$columnSearch,$query)
{
parent::__construct();
$this->columnOrder = $columnOrder;
$this->columnSearch = $columnSearch;
$this->query = $query;
}
/**
* Generate db query
*
* @return object
*/
private function getDatatablesQuery()
{
$i = 0;
foreach ($this->columnSearch as $item) {
if(@$_POST['search']['value']) {
if($i===0) {
$this->query->group_start();
$this->query->like($item, $_POST['search']['value']);
} else {
$this->query->or_like($item, $_POST['search']['value']);
}
if(count($this->columnSearch) - 1 == $i)
$this->query->group_end();
}
$i++;
}
if(isset($_POST['order'])) {
$this->query->order_by($this->columnOrder[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
} else if(isset($this->order)) {
$order = $this->order;
$$this->query->order_by(key($order), $order[key($order)]);
}
}
/**
* Generate db result
*
* @return integer
*/
public function getDatatables()
{
$this->getDatatablesQuery();
if(@$_POST['length'] != -1) $this->query->limit(@$_POST['length'], @$_POST['start']);
$query = $this->query->get();
return $query->result();
}
/**
* Count filtered rows
*
* @return integer
*/
public function countFiltered()
{
$query = $this->query->get();
return $query->num_rows;
}
/**
* Count all rows
*
* @return integer
*/
public function countAll()
{
return $this->query->count_all_results();
}
}
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/73637131/codeigniter-3-no-table-used-when-i-tried-to-reuse-database-intstance[/url]