HamzaDev
HamzaDev

Reputation: 21

Class doesnt exist

i tried this method implementing a repository and i get this error: Class "App:Product" doesn't exist, even though the ide suggested i put it in the method getRepository(). here's the code:

/**
* @Route("/list", name= "Product")
*/
public function index(ManagerRegistry $doctrine): Response 
{
    $repository=$doctrine->getRepository('Product:class');
    $products=$repository->findAll();
    return $this->render('product/index.html.twig',[
       'products'=>$products
    ]);
}

Upvotes: 0

Views: 573

Answers (1)

jona303
jona303

Reputation: 1568

Following the doc, you better use a non string class identifier and add a use statement to import the product class.

// ...
$products = $doctrine->getRepository(Product::class)->findAll();

https://symfony.com/doc/5.4/doctrine.html#fetching-objects-from-the-database

You can also inject the repository itself in your method

public function index(ProductRepository $productRepository): Response {
//...

Upvotes: 3

Related Questions