I'm trying to use
file_get_contents to reference a
.json file in my module.
My directory structure is as follows
my custom field which is trying to reference the json file
my json file
If I use
$json = 'modules/mod_kou_stack_exchange/media/js/sites.json';
$json = file_get_contents($json);
PHP cannot find the file. I think perhaps because it is trying to reference it from the original file location. If I put the full location in the file it works, so long as I add an exception in Admin Tools. I don't want to hard code the URL as it might be used on other sites.
So then I have the option to use the URI function in Joomla.
However, if I try to use
$uri = Uri::getInstance();
$url = $uri->toString();
within my code, it is then not accessible within the class that I am using
class JFormFieldStackexchangesites extends JFormFieldList
If I try to add
$url within the class that doesn't work either.
I'm sure this must be something to do with scope but having tried a few different ways I can't understand how to get it working.
Can anyone help me to understand how to get this working? And can anyone help me to understand why a relative path doesn't work?