Using Doctrine With laminas project issue : "Class does not exist"

hi i am new user of laminas.
I just installed Doctrine with my Laminas project. I added a database connection and generated my entities in the Application folder (Application\Entity). I added my entities settings to the module.config.php file in the Application folder. I created a new User and everything, including routing, is working fine. However, when I try to fetch all data from my table to view, the screen displays an error: ‘Class ‘Application\Entity\User’ does not exist’.
i can’t find any solution

module
|_Application
   |_config
   |_Entity
   |_src
   |_view
|_User
   |_config
   |_src
   |_view
`entities settings : namespace : Application <in Application folder - module.config.php>`
'doctrine' => [
        'driver' => [
            __NAMESPACE__ . '_driver' => [
                'class' => AnnotationDriver::class,
                'cache' => 'array',
                'paths' => [__DIR__ . '/../Entity']
            ],
            'orm_default' => [
                'drivers' => [
                    __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
                ],
            ],
        ],
    ],

UserManager

namespace : User\Manager
public function listUsers()
    {
        $query = $this->entityManager->getRepository(User::class)->findAll();
        return $query;
   }

UserController

namespace : User\Controller
public function listUserAction()
    {
        $data = $this->usermanager->listUsers();
        var_dump($data);
        die();
        $view = new ViewModel([
            'users' => $data
        ]);
        return $view;
    }

Entity Folder => Path : Application\Entity

Hey @Super0Yt,

welcome to the laminas forums.

The first thing I see is, that the Entity folder is right under the Application folder. That could be the cause, that your entities could not be found. The Entity folder has to be a subfolder of the src folder. Just move the Entity folder into the src folder and try again. I guess, that it is worken then.

The laminas autoloading is looking into the src folder of every module implemented by default.

2 Likes

thank you very much it is working now