【发布时间】:2017-10-17 05:59:14
【问题描述】:
这是我的控制器
public function showCategoryJson(){
$this->load->model('user/category_model');
$data[] = $this->category_model->displayCategory();
echo json_encode($data);
}
我的模型
function displayCategory(){
$query = $this->db->get('categories');
$res = $query->result_array();
return $res;
}
和我的观点
<?php
$url = site_url('user/category/showCategoryJson'); // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
// echo $data;
$results = json_decode($data); // decode the JSON feed
foreach ($results as $key => $cat) {
?>
<tr class="odd gradeX">
<td><?php echo $cat[$key]->categoryname; ?></td>
<td><?php echo $cat[$key]->username; ?></td>
<td class="center"><a class="btn btn-success fa fa-edit"></a> <a class="btn btn-danger fa fa-trash delete" id="<?php echo $cat[$key]->categoryid; ?>"></a></td>
</tr>
<?php } ?>
【问题讨论】:
标签: json codeigniter-3