CodeIgniter Forums
How to load json file in codeigniter… newbie - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: How to load json file in codeigniter… newbie (/thread-55915.html)



How to load json file in codeigniter… newbie - El Forum - 11-16-2012

[eluser]danny_ci[/eluser]
Hi, everyone…
I want to ask something about how to load json file in codeigniter
But before load the json file, i want to pass some data to json file
Any idea for this??

Thanks before

Here is some code to load json file in jquery event calendar

Code:
$("#calendar").eventCalendar({
  eventsjson: 'file.json' //here to load json file
});



How to load json file in codeigniter… newbie - El Forum - 11-17-2012

[eluser]NeoArc[/eluser]
Code:
$data = json_decode(file_get_contents('file.json'));
var_dump($data);



How to load json file in codeigniter… newbie - El Forum - 11-18-2012

[eluser]Ajaxboy[/eluser]
If you use Cjax (http://ellislab.com/forums/viewthread/229077/), can do this to pass data:

Code:
$("#calendar").eventCalendar({
  eventsjson: 'ajax.php?calendar/json/var1/var2'
});



Code:
Class Calendar Extends CI_Controller {

  function json($var1, $var2)
  {
    $data = array();
    
    $data['var1' = $var1;
    $data['var2'] = $var2;
    
    $data['other_data'] = 'some data';

    return $data; //return a json formatted object
  }

}