I am new in CodeIgniter. I want to put JSON data from controller to view in CodeIgniter. So far, I can show the JSON data directly from my controller.
Here is my code for controller:
public function index()
{
//$this->load->view('test');
$get_url_service = $this->url_service->GetUrl('KategoriRetrieve');
$get_json = file_get_contents($get_url_service);
$get_data = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($get_json, TRUE)), RecursiveIteratorIterator::SELF_FIRST);
//print_r ($get_data);
foreach ($get_data as $key => $val) {
if(is_array($val))
echo "$key:"."<br />";
else
echo "$key => $val"."<br />";
}
}
The function GetUrl()
is loaded from my custom library called url_service. Here is my library url_service.php
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Url_service
{
public function GetUrl($param){
//http://localhost:90/Aset/json/reply/
return "http://localhost:90/kugi_deployment/api/json/reply/".$param;
}
}
Like I already said above, I want to show the data in view. How can I do that? Can anyone help me to do this? Thanks