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 !!