I am getting started with the F3 Framework (Fat Free Framework) and so far it's great. Simple and light. I set it up so that my controllers are in a separate folder App/Controllers and that is working great using classes and namespaces. On thing I'm having trouble with is reading a JSON file from one of those controllers. My code is below:
$json = $f3->read('settings/templates.json');
$templates = json_decode($json);
var_dump($templates);
$fields = $templates->$template->fields;
I tried it like that and like this
$json = file_get_contents('settings/templates.json');
$templates = json_decode($json);
var_dump($templates);
$fields = $templates->$template->fields;
But either way I get a file not found error. So somehow, F3 is not finding the file. I'm not sure if I need to include this in the AUTOLOAD or if there is some better way to do this.
I tried it as a database like so and it finds the file, but somehow this doesn't seem right:
$db = new \DB\Jig ( 'settings/' , \DB\Jig::FORMAT_JSON );
$user= new \DB\Jig\Mapper($db, 'templates.json');
var_dump($templates);
$fields = $templates->$template->fields;
It seems like I shouldn't be using the DB class and Jig just to read a simple JSON file. Can someone please shed some light on this?
EDIT: Ok the answer below helped, but in my particular case, everything (the syntax) was right. I think the reason it didn't work was because I had the paths wrong in this line of my index.php
$f3->set('AUTOLOAD','App/Controllers/');