Jamel Mustapha
Jamel Mustapha

Reputation: 77

Undefined method The method name must start with either findBy or findOneBy

i want to delete a product after a known date this is my Controller :

public function indexAction()
{
    $em = $this->getDoctrine()->getManager();
    $productsInitial = $em->getRepository('ProductBundle:Product')->findAll();

    $productsAfterdelete=$em->getRepository('ProductBundle:Product')->deleteApresDure($productsInitial);


    return $this->render('product/index.html.twig', array(
        'products' => $productsAfterdelete,
    ));
}

my function in repository class :

public function deleteApresDuree($products)
    {
        $datenow=new \DateTimeImmutable();
        foreach ($products as $produit){
            $datecreation=$produit->getCreatedDate();
            $result = $datecreation->format('Y-m-d');
            $date_fin = date('Y-m-d', strtotime($result.' +15 days'));
            if ( $datenow>$date_fin )
            {
                unset($products[$produit]);
                array_values($products);

            }
        }
    return $products;

    }

/** * Produit * @ORM\Entity(repositoryClass="\ProductBundle\Repository\ProductRepository") * @Vich\Uploadable * @ORM\Table(name="produit") */

error :

Undefined method 'deleteApresDure'. The method name must start with either findBy or findOneBy!

pleaaase ANY HELP !!

Upvotes: 2

Views: 5960

Answers (1)

ste
ste

Reputation: 1529

you should change repositoryClass="\ProductBundle\Repository\ProductRepository with repositoryClass="ProductBundle\Repository\ProductRepository

Upvotes: 1

Related Questions