2017-02-18 58 views
2

開始我想知道日期 後刪除一個產品,這是我的控制器:未定義的方法,該方法的名稱必須以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 !!

+0

改變repositoryClass="\ProductBundle\Repository\ProductRepository錯誤消息意味着你的資料庫沒有正確映射到實體。確保緩存已被清除,並且沒有輸入錯誤。其他更晦澀的事情也可能是錯誤的。有幾百個其他問題的問題完全相同。 – Cerad

+0

我提到了!我沒有任何註釋問題,我在其他幾個人的問題中搜索,這是一個不同的問題。 –

+0

任何方式我複製我的功能到控制器,它的工作thnx的方式 –

回答

1

你應該repositoryClass="ProductBundle\Repository\ProductRepository

+0

謝謝,但我做了註釋的所有可能性同樣的錯誤 –

+0

一定要清理緩存,或做測試開發環境(它總是重新生成緩存)。 – ste

+0

如果它不工作發佈**完整**實體和存儲庫文件。 – ste

相關問題