OpenWeatherMap Class Not Found Error (NOT Installed through Composer)
GermanPearls opened this issue · 3 comments
I wasn't able to install this through composer so I used php-download.com to pull the package from packagist, downloaded it as a zip and saved it on my server.
Here's the code where I called the API:
use cmfcmf_openweathermap_php_api_2_4_0\vendor\cmfcmf\openweathermap_php_api\Cmfcmf\OpenWeatherMap_Class;
use cmfcmf_openweathermap_php_api_2_4_0\vendor\cmfcmf\openweathermap_php_api\Cmfcmf\OpenWeatherMap\Exception as OWMException;
//Run Google Calendar API and Fetch Calendar Events
include '\cmfcmf_openweathermap_php_api_2_4_0\vendor\autoload.php';
$owm = new OpenWeatherMap('my API key in here');
I'm getting an error of "Fatal error: Class 'OpenWeatherMap' not found..."
I've tried several variations but can't get it to work. I wonder if it's related to my file structure. The webpage 'weather-test.php' is in the root folder. Here is the full structure showing where vendor/autoload.php and OpenWeatherMap are located.
Root Dir
file: weather-test.php
-\cmfcmf_openweathermap_php_api_2_4_0
--\vendor
file: autoload.php
---\cmfcmf
----\openweathermap_php_api
-----\Cmfcmf
------\OpenWeatherMap
OpenWeatherMap_Class.php
Thank you in advance.
Hi @GermanPearls,
I highly recommend to use composer – what exactly did not work when you tried?
I've also looked at the download provided by php-download.com: You'll have to first require("vendor/autoload.php")
before you can use any of the classes of this project. Then you should use these imports:
use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Exception as OWMException;
Thank you for your time @cmfcmf .
I didn't use composer because I have no command line access to my server.
I've tried what you suggested. However, because of my file structure, I used:
include '\cmfcmf_openweathermap_php_api_2_4_0\vendor\autoload.php';
I still get the class not found error. Any other thoughts?
Thank you.
It's working.
I'm not sure the root cause of the original error but here are the changes I made to get it to finally work.
I removed the extra directory level. In addition, I found that, during troubleshooting, I changed the directory name to include _ instead of -
Thank you for your help (and for the use of the package).