CodeIgniter — Объект не извлекается из базы данных в формате JSON

Я пытаюсь получить данные о клиентах из базы данных в формате JSON, но объект не извлекается.

Это мой модельный метод для захвата клиента:

function getCustomers($per_page=0,$page=0, $key=0,$company="",$type='billing',$order_by="id",$order="desc"){
if(!empty($per_page) && !empty($page) ){
$start=0;
if($page>1)
$start=(($page-1)*$per_page);
$this->db->limit($per_page, $start);
}
if (!empty($company)) {
$this->db->like('company', $company, 'both');
}
if (!empty($type)) {
$this->db->where('type', $type);
}

$this->db->where('is_active', 1);
$this->db->order_by($order_by,$order);
$query = $this->db->get("customers");
$records=$query->result_array();
if(empty($key)){
return $records;
}
$newArray = array();
foreach ($records as $record) {
$id = $record['id'];
$newArray[$id] = $record;
if (!empty($record['lane_lists'])) {
$newArray[$id]['unserialized_lanes'] = unserialize($record['lane_lists']);
} else {
$newArray[$id]['unserialized_lanes'] = array();
}
if (!empty($record['comment'])) {
$newArray[$id]['unserialized_comment'] = unserialize($record['comment']);
} else {
$newArray[$id]['unserialized_comment'] = array();
}
if (!empty($record['created_at'])) {
$newArray[$id]['since'] = date('m/d/Y', $record['created_at']);
} else {
$newArray[$id]['since'] = "";
}

}

return $newArray;
}

Вот моя функция подсчета в модели

    function getCustomersCount($company="", $type='billing'){
if (!empty($company)) {
$this->db->like('company', $company, 'both');
}
if (!empty($type)) {
$this->db->where('type', $type);
}

$this->db->select('count(*) as count');
$query = $this->db->get("customers");
return $query->row_array();
}

Это мой контроллер для отображения информации о клиентах:

    public function index($type='billing', $page=1){

$company="";
if(!empty($_GET['company']))
$company=$_GET['company'];
$per_page=$this->config->item('per_page_limit');
$total_rows = $this->admin_model->getCustomersCount( $company, $type);
$total_count=$total_rows['count'];
if($total_count<=($per_page*($page-1)) && $total_count > 0){
$currentPage=($total_count%$per_page)==0?($total_count/$per_page):ceil($total_count/$per_page);
redirect(base_url().'admin/customers/index/'. $type .'/'.$currentPage);
}
$links=paginationLink($this,'admin/customers/index/' . $type . '/', $total_count,$per_page);
$records = $this->admin_model->getCustomers($per_page, $page,0,$company, $type,"company");


if ($type == 'billing') {
$submenu = 'bill_to_customers';
$pageTitle = 'Bill To Customers';
} else if ($type == 'shed') {
$submenu = 'pickup_drop_customers';
$pageTitle = 'Pickup Drop Customers';
} else if ($type == 'shipper') {
$submenu = 'shipper_customers';
$pageTitle = 'Shipper Customers';
} else {
$submenu = '';
$pageTitle = 'Customers';
}
$this->data=array('page_title'=>$pageTitle,'records'=>$records,'main_menu'=>'customers','submenu'=>$submenu,'links'=>$links, 'type' => $type);
layout($this,'customers/list');
}

В моей таблице клиентов есть данные, но когда я использую console.log() чтобы увидеть его, я не вижу объект.

<script type="text/javascript">
var app = new Vue({
el: "#customerList",
data: {
loginUserType: <?php echo $this->session->userdata('logged_in')['type']; ?>,
customers: <?php if(!empty($records)) { echo json_encode($records); } else {echo '{}';} ?>,
customerSelected: {},
customerType: '<?php if (!empty($type)) echo $type; ?>',


links:  <?php if(!empty($links)) echo json_encode($links); else echo '{}'; ?>,
states: <?php echo json_encode($this->config->item('us_states')); ?>,

},

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector