和型号页面是:
public function categories() {
$this->load->model('categories_model');
try {
$categories = $this->categories_model->get_all();
if (!empty($categories)) {
$this->result = $categories;
} else {
throw new Exception('No data founds');
}
} catch (Exception $e) {
$this->error = $e->getMessage();
}
// array data
return $this->_prepare_return_data();
}
我是codeigniter和json的初学者。你能帮我看看如何在视图页面中显示类别
答案 0 :(得分:0)
一个基本的例子。
控制器:
function categories() {
$this->load->model('categories_model');
$data = $this->categories_model->getCategories();
$json = json_encode($data);
header('Content-Type: application/json');
print $json;
}
模型:
function getCategories() {
$q = $this->db->get('categories');
return $q->result_array();
}