skymeyer / Vatsimphp

Vatsimphp - VATSIM data parser
http://skymeyer.github.io/Vatsimphp/
Apache License 2.0
29 stars 7 forks source link

Call to a member function search() on null, when trying to extract pilot/controller data #19

Closed h-okon closed 5 years ago

h-okon commented 5 years ago

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.

skymeyer commented 5 years ago

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:

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:

asciicast

skymeyer commented 5 years ago

Close since no response - feel free to reopen when needed.

GeorgeBarlow commented 5 years ago

Got this same issue, any fix?

skymeyer commented 5 years ago

Can you give me a code snippet ?

GeorgeBarlow commented 5 years ago

https://raw.githubusercontent.com/LondonHeathrowACDM/Dashboard/master/app/Http/Controllers/System/DashboardController.php

That’s my dashboard controller which is where the error is coming from.

h-okon commented 5 years ago

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.

GeorgeBarlow commented 5 years ago

What perms did u give it Hubert?

h-okon commented 5 years ago

chmod -R +w <here following directories>