Reputation: 672
Good evening!
I have a little problem accessing custom classes in symfony2.1.6 using the autoloader. What I need to do is access the Mangress/src/Qkprod/Classes/api/APIEntry.php class from within the DefaultController. Apparently I am too stupid to find a way to extend the autoload.php to do that. Now I am at a point where I have been reading so many blogposts and solutions that I don't know anymore what to do anymore...
My file structure looks as follows:
Mangress -app -src -Qkprod -MangressBundle -Controller, Entity, Resources, Tests -Classes -api -APIEntry.php -db -security -QkprodMangressBundle.php -vendor -webThe Classes folder contains all the classes I have written so far.
What I have read so far was that I need to register the Namespaces of
the classes to load in the Mangress/app/autoload.php
Autoloading a class in Symfony 2.1
$loader->add('Qkprod\MangressBundle\api', DIR.'/../src/Qkprod/MangressBundle/Classes/api/'); Though this seems to be wrong..
Is there something wrong with my naming or understanding of symfony? I register the Namespace "Qkprod\MangressBundle\api" to the autoloader so that symfony knows where to look when
use Qkprod\MangressBundle\api\APIEntry;
So it has to look in my Mangress/src/Qkprod/MangressBundle/Classes/api folder am I wrong?
I would really appreciate some guidance :)
Upvotes: 0
Views: 156
Reputation: 5668
Why aren't you using the directory structure recommended by symfony developers?
And not even just symfony developers, this structure is called PSR-0, and is adopted by many PHP frameworks.
If you stay with the conventions, the default autoloader will load your classes just fine, and other developers will understand your code more easier.
Just remove your "Classes" directory, and move everything from it a level upwards:
Mangress
-app
-src
-Qkprod
-MangressBundle
-Controller, Entity, Resources, Tests
-Api
-APIEntry.php
-Db
-security
-QkprodMangressBundle.php
-vendor
-web
This way when you write
use Qkprod\MangressBundle\Api\APIEntry
It will know where to look.
Upvotes: 1