-
Notifications
You must be signed in to change notification settings - Fork 47
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
Including a class #36
Comments
Classes need the correct namespace at the top of the file, otherwise the auto-loader will be looking in the wrong place. Where is this current class defined and what namespace have you given it? As an example If it's a command the namespace should be "Command" and the file should be contained inside the Classes/Command/ directory. |
Hey, I'm basically trying to implement https://github.com/J7mbo/twitter-api-php into the project in the form of a !twitter command. I'm just unsure how to include the required php (TwitterAPIExchange.php) file for it. |
OK, where have you put the file in the directory structure? |
Everywhere. I either get a duplicate class error or an autoloader error. Where should I put it? |
I think you might be misunderstanding me. Where have you put the file "TwitterAPIExhange.php"? If you put it in the same folder as the Autoloader.php and then when you want to use it call "new \TwitterAPIExchange($settings);". The auto-loader will then kick in on the first load and load the file once. |
The point of an auto-loader is to never have to use require/require_once/include or include_once yourself which tidies up the code and also avoids the multiply defined classes problems. |
Oh, excellent. Thanks! |
No problem. =) I assume your issue is now resolved? |
Hey, I'd like to use 'simple_html_dom.php' and it's not a class. I'm not having much luck guessing where to put him. Could you spoon-feed me? :) |
Do you want to use that for a command? |
Hey, I'm trying to add twitter functionality, but I'm having real trouble with autoloader.php trying to load my class or something?
PHP Fatal error: Uncaught exception 'Exception' with message 'File: "/home/steve/Desktop/bot/Classes/TwitterAPIExchange.php" not found.' in /home/steve/Desktop/bot/Classes/Autoloader.php:40
How can I do this?
The text was updated successfully, but these errors were encountered: