Reputation: 8715
I am trying to organise my app a bit better by putting models and controllers in subdirectories. I thought it didn't matter if they were in subdirectories as long as the namespace is correct, but now that I've moved them I'm getting a class not found error.
I have tried running composer dumpautoload
several times, but it's still not working.
Here is my directory structure:
Since I have made the new directory Managers and moved those two models in there, When I reference the FieldManager
class from EntryStructure, I get the not found error.
Code in EntryStructure.php:
namespace Pascall\ICMS\Models;
use Pascall\ICMS\Models\FieldManager;
class EntryStructure
{
function index(){
new FieldManager(); // class not found
}
}
Code in FieldManager.php:
namespace Pascall\ICMS\Models;
class FieldManager {
//
}
Why is it not finding the FieldManager
class when it is explicitly referenced in the use
statement and they share the same namespace?
Upvotes: 0
Views: 1895
Reputation: 19285
If your Models directory follow the PSR-4 specifications, the namespace in both of your classes should follow the class file path, so it should be:
namespace Pascall\ICMS\Models\Managers;
Then, in EntryStructure
class you should use:
use Pascall\ICMS\Models\Managers\FieldManager;
Upvotes: 0
Reputation: 4435
Your use should be
use Pascall\ICMS\Models\Managers\FieldManager;
instead
use Pascall\ICMS\Models\FieldManager;
Upvotes: 1