Call to a member function search() on null, when trying to extract pilot/controller data
h-okon opened this issue · 8 comments
My code currently looks like this:
https://pastebin.com/dt73rn4T
And every time I try to run it I'm getting:
Fatal error: Call to a member function search() on null in /home/vatsim/html/stands/vendor/skymeyer/vatsimphp/src/Vatsimphp/VatsimData.php on line 291.
I can't extract any pilots nor controllers.
I tried the following code which worked for me based on your above example:
<?php
require_once 'vendor/autoload.php';
use Vatsimphp\VatsimData;
$vatsim = new VatsimData();
$vatsim->loadData();
$pilots = $vatsim->getPilots()->toArray();
foreach ($pilots as $pilot) {
echo "{$pilot['callsign']} => {$pilot['latitude']} {$pilot['longitude']} \n";
}
printf("\nTotal pilots: %d\n", count($pilots));
Couple of questions/comments which might help:
- Which PHP version are you running ?
- Do you have php-curl installed ?
- Are there any PHP notices/warnings in your web server log ?
- Make sure
vendor/skymeyer/vatsimphp/app/cache
andvendor/skymeyer/vatsimphp/app/logs
are both writable (*)
Check the vatsimphp.log
file to see if the code was able to properly fetch the data from the Vatsim network (see https://github.com/skymeyer/Vatsimphp/blob/1.x/docs/tutorial.md#logging)
Here is a screencast example which shows you the above code and where the cached data and logs are:
Close since no response - feel free to reopen when needed.
Got this same issue, any fix?
Can you give me a code snippet ?
That’s my dashboard controller which is where the error is coming from.
In my case the permissions were broken.
Fixed by correctly giving chmod to:
vendor/skymeyer/vatsimphp/app/cache
and
vendor/skymeyer/vatsimphp/app/logs
Thanks for help.
What perms did u give it Hubert?
chmod -R +w <here following directories>