5.7 how do you include and instantiate a custom class (application/src). as in not a core classs (concrete/src)

Permalink 1 user found helpful
I have an instagram class located in application/src/instagram.php
The name of the class is Instagram

Im trying to use this class inside my theme....
I modeled this after an example on this page

use \application\Core\Instagram;
$instagram = new Instagram();

Im getting the error:
Class 'application\Core\Instagram' not found

what am I doing wrong?

View Replies: View Best Answer
MichaelG replied on at Permalink Reply
your instagram.php file should look something like this

namespace Application\Src;
class Instagram {}

is that the case? If so, you call the use in Upper camelcase such as

use \Application\Src\Instagram
glin425 replied on at Permalink Reply 1 Attachment
I have added in the namespace call in the top of my instagram class as you suggested and im now getting an error:
syntax error, unexpected '/', expecting T_STRING or T_NS_SEPARATOR or '{'

also I have attached a screenshot

so now i have...

instagram class
namespace /Application/Src;
class Instagram {}?>

file trying to use the instagram class:
use \Application\Src\Instagram;
$instagram = new Instagram();
MichaelG replied on at Permalink Best Answer Reply
sorry, I mispoke
namespace should be Application\Src;
backslashes all the way, and you shouldn't need it right before Application
daenu replied on at Permalink Reply
Hi there
Similar problem here. My class file is located at

using 5.7.4
namespace Application\Src\Paypal;
class Paypal {

Trying to use it in a single page like so:
$paypal = new Application\Src\Paypal\Paypal();
$paypal = new \Application\Src\Paypal\Paypal();

Class 'Application\Src\Paypal\Paypal' not found
What am I missing?
JohntheFish replied on at Permalink Reply
in the file path, everything after /src/ needs the same capitalisation as the namespace.
daenu replied on at Permalink Reply
Thank you! That was it. And if I had a look at /concrete/src I should have seen this.....
glin425 replied on at Permalink Reply
awesome, that worked thanks a bunch!

spent a few hours on that..... glad to be getting past it.
jgarcia replied on at Permalink Reply
Just a heads up folks - this has changed in version 8. The files will still live in application/src, but the namespacing has changed. See:https://documentation.concrete5.org/developers/extending-concrete5-w...