Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenWeatherMap Class Not Found Error (NOT Installed through Composer) #133

Closed
GermanPearls opened this issue May 2, 2019 · 3 comments
Closed

Comments

@GermanPearls
Copy link

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.

@cmfcmf
Copy link
Owner

cmfcmf commented May 4, 2019

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;

@GermanPearls
Copy link
Author

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.

@GermanPearls
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants