2016-02-24 114 views
0

我的問題是,我試圖執行一個命令,但是給我的下一個錯誤:嘗試加載類錯誤的Symfony 2

Attempted to load class "XMLReport" from namespace "BusinessName\Core\LibraryDatabaseBundle\Repository". Did you forget a "use" statement for "BusinessName\Core\LibraryDatabaseBundle\Entity\XMLReport"?

repository類使用命名空間:

namespace Mundoreader\Core\LibraryDatabaseBundle\Repository; 

use Doctrine\ORM\Query\QueryException; 
use Doctrine\ORM\Query\ResultSetMapping; 
use Doctrine\ORM\QueryBuilder; 
use Mundoreader\Core\LibraryDatabaseBundle\Entity\Library; 

/** 
* Class XMLReportRepository 
* 
*/ 
class XMLReportRepository extends AbstractRepository 
{/*code 
} 

命令類:

class GenerateXMLCommand extends AbstractCommand 
{ 

    protected function configure() 
    { 
     $this 
      ->setName('library:reports:generateXML') 
      ->setDescription('Generate XML'); 
    }  
protected function execute(InputInterface $input, OutputInterface $output) 
     { 
      $statusToDo   = $this->xmlReportRepo->countAllStatusToDo(); 

      if($statusToDo) 
      { 

       //XML BBDD 
       $emXML   = new XMLReport(); 
       $libraryXML  = $emXML->getLibrary(); 
       $isbnXML  = $emXML->getISBN(); 
       $toDateXML  = $emXML->getReportDateEnd(); 
       $fromDateXML = $emXML->getReportDateStart(); 
       $arrayXMLInfo = array(
        ['fromDate'] => $fromDateXML, 
        ['toDate']  => $toDateXML, 
        ['library']  => $libraryXML, 
        ['isbn']  => $isbnXML 
       ); 
    /*More Code 
    } 

我不知道哪裏是錯誤的,因爲我在調用庫:

$statusToDo   = $this->xmlReportRepo->countAllStatusToDo(); 

在擴展類我的路線:

abstract class AbstractCommand extends ContainerAwareCommand 
{ 
public function setContainer(ContainerInterface $container = null) 
    { 
     $this->xmlReportRepo = $this->doctrine->getRepository('MrLibraryDatabaseBundle:XMLReport'); 
    } 
} 

PD:對不起,我的英語不好。

+0

您在GenerateXMLCommand的頂部添加了「使用BusinessName \ Core \ LibraryDatabaseBundle \ Entity \ XMLReport」嗎? – Twifty

+0

是的,我做過。所以我不知道問題在哪裏。 – Sermanes

+0

看起來您嘗試在XMLReport XMLReportRepository中使用XMLReport類。您可以顯示XMLReportRepository類代碼並將Block用於GenerateXMLCommand類 –

回答

1

請檢查您的映射定義中的存儲庫類。應該是這樣的:

// src/AppBundle/Entity/Product.php 
namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity(repositoryClass="AppBundle\Entity\ProductRepository") 
*/ 
class Product 
{ 
    //... 
} 
+0

是的,我擁有它:S – Sermanes