Пожалуйста, помогите, я не могу решить, как правильно конвертировать мой старый PHP в Codeigniter, чтобы получить результат JSON, как показано ниже.
{"data":[{"Category":{"Category_ID":"3","Category_name":"Camera","Category_image":"upload\/images\/7089-2015-07-09.png"}},{"Category":{"Category_ID":"9","Category_name":"Cars","Category_image":"upload\/images\/7789-2015-07-09.png"}},{"Category":{"Category_ID":"4","Category_name":"Clothes","Category_image":"upload\/images\/9350-2015-07-09.png"}},{"Category":{"Category_ID":"1","Category_name":"Computer","Category_image":"upload\/images\/1843-2015-07-09.png"}},{"Category":{"Category_ID":"7","Category_name":"Music","Category_image":"upload\/images\/8666-2015-07-09.png"}},{"Category":{"Category_ID":"5","Category_name":"Other","Category_image":"upload\/images\/6260-2015-07-09.png"}},{"Category":{"Category_ID":"2","Category_name":"Smartphone","Category_image":"upload\/images\/3025-2015-07-09.png"}},{"Category":{"Category_ID":"8","Category_name":"Sports","Category_image":"upload\/images\/5354-2015-07-09.png"}}]}
Это моя версия PHP
<?php
include_once('../includes/connect_database.php');
include_once('../includes/variables.php');
$sql_query = "SELECT *
FROM tbl_category
ORDER BY Category_name ASC ";
$result = $connect->query($sql_query) or die ("Error :".mysql_error());
$categories = array();
while($category = $result->fetch_assoc()) {
$categories[] = array('Category'=>$category);
}
// create json output
$output = json_encode(array('data' => $categories));
//Output the output.
echo $output;
include_once('../includes/close_database.php');?>
Это мойверсия кодового ключа
public function prop_get() {
//$data = null;
$category = $this->db->get('kategori')->result();
//$category = $this->Wilayah_model->get_category2();
$categories[] = array('Category' => $category);
$this->response(array('data' => $categories));
}
Спасибо