開始我想知道日期 後刪除一個產品,這是我的控制器:未定義的方法,該方法的名稱必須以findBy或findOneBy
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,
));
}
我的函數庫類:
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;
}
/** *產品 * @ORM \ Entity(repositoryClass =「\ ProductBundle \ Repository \ ProductRepository」) * @Vich \ Uploadable * @ORM \表(名稱= 「produit」) */
錯誤:
未定義方法 'deleteApresDure'。方法名稱必須以findBy或findOneBy開頭!
pleaaase ANY HELP !!
改變
repositoryClass="\ProductBundle\Repository\ProductRepository
錯誤消息意味着你的資料庫沒有正確映射到實體。確保緩存已被清除,並且沒有輸入錯誤。其他更晦澀的事情也可能是錯誤的。有幾百個其他問題的問題完全相同。 – Cerad我提到了!我沒有任何註釋問題,我在其他幾個人的問題中搜索,這是一個不同的問題。 –
任何方式我複製我的功能到控制器,它的工作thnx的方式 –