I'm trying to get data from JSON file manually, not from URL. I use function file_get_contents. And I got error :
Message: file_get_contents(sso.json): failed to open stream: No such file or directory
Even though the path is correct. This is my structure project :
-> kalenderkerja
-> application
-> controllers
-> agendakerja
Kalender.php
sso.json
-> assets
-> ...
This is my code in function user() in file Kalender.php
public function user() {
$url = 'sso.json';
$data = file_get_contents($url);
$characters = json_decode($data, true);
echo $characters['name'];
}
And I call the controller in browser localhost/kalenderkerja/agendakerja/kalender/user and I got this error :
If you change to
$url = __DIR__.'/sso.json';
This should work. You can learn more about magic constants from HERE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With