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....
Example:
I modeled this after an example on this page
http://www.concrete5.org/documentation/developers/5.7/environment/a...

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

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

what am I doing wrong?

 
MichaelG replied on at Permalink Reply
MichaelG
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
<?php
namespace /Application/Src;
class Instagram {}?>


file trying to use the instagram class:
<?php
use \Application\Src\Instagram;
$instagram = new Instagram();
var_dump($instagram);exit;
?>
MichaelG replied on at Permalink Best Answer Reply
MichaelG
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
daenu
Hi there
Similar problem here. My class file is located at
/application/src/paypal/paypal.php

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();
or
$paypal = new \Application\Src\Paypal\Paypal();


Error:
Class 'Application\Src\Paypal\Paypal' not found
What am I missing?
JohntheFish replied on at Permalink Reply
JohntheFish
in the file path, everything after /src/ needs the same capitalisation as the namespace.
daenu replied on at Permalink Reply
daenu
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
jgarcia
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...