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

345 Views Asked by At

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`
1

There are 1 best solutions below

1
Marcel On

As this question was already answered in the Laminas forums, I think I should complete this question here, too.

Your folder structure is wrong. The folder where your entities are stored must be a subfolder of the src folder of your application.

./module/Application/src/Entity/User.php

In Laminas projects all business logic is stored in the src folder. The Laminas autoloading will try to receive all classes from there.