2016-08-19 4 views
1

저는 독트린과 교향곡을 처음 사용합니다. doctrine ORM을 사용하여 두부 작동으로 작은 응용 프로그램을 만들었습니다. 내 삽입 작업이 작동하지만 내 목록 작업이 내가 여기에 내 코드를 붙여 것이다 오류클래스가 getRepository에 존재하지 않습니다. doctrine

[Doctrine\Common\Persistence\Mapping\MappingException]
Class 'Tab' does not exist

로 던졌습니다 : 내 모델 파일 :의/var/www/html/silexapp/응용 프로그램/Tnq/도도/모델/Tab.php

<?php 
    namespace Tnq\Todo\Model; 
    // app/Tnq/Todo/Model/Tab.php 
    /** 
    * @Entity(repositoryClass="Repository_TabRepository")  
    @Table(name="tab") 
    */ 
    class Tab 
{ 
/** @TAB_ID 
* @Id @Column(type="integer") @GeneratedValue 
* @var int 
*/ 
protected $id; 
/** 
* @Column(type="string") 
* @var string 
*/ 
protected $description; 
/** 
* @Column(type="string") 
* @var string 
*/ 
protected $tabname; 

public function getId() 
{ 
    return $this->id; 
} 

public function getDescription() 
{ 
    return $this->description; 
} 

public function setDescription($description) 
{ 
    $this->description = $description; 
} 

public function setTabname($tabname) 
{ 
    $this->tabname = $tabname; 
} 

public function getTabname() 
{ 
    return $this->tabname; 
} 

} 
난 내 두부 작업을 할

내 교리 ORM 파일 : /var/www/html/silexapp/app/Tnq/Todo/Command/Tabcommand.php

<?php 
    namespace Tnq\Todo\Command; 

    require_once "../vendor/autoload.php"; 
    //require_once '/var/www/html/silexapp/app/web/bootstrap.php'; 


    use Tnq\Todo\Model as tabmodel; 

    use Doctrine\ORM\Tools\Setup; 
    use Doctrine\ORM\EntityManager; 

    use Symfony\Component\Console\Command\Command; 
    use Symfony\Component\Console\Input\InputInterface; 
    use Symfony\Component\Console\Output\OutputInterface; 
    use Symfony\Component\Console\Input\InputArgument; 
    use Symfony\Component\Console\Input\InputOption; 
    use Symfony\Component\Console\Input\InputDefinition; 

class Tabcommand extends Command 
{ 
protected function configure() 
{ 
    $this 
     ->setName('todo') 
     ->setDescription('Tab Creation') 
     ->setDefinition(
      new InputDefinition(array(
       new InputOption('create', 'a'), 
       new InputOption('list', 'b'), 
       new InputOption('update', 'c'), 
       new InputOption('delete', 'd'), 
      )) 
     ) 

    ->addOption(
     'tabname', 
     null, 
     InputOption::VALUE_REQUIRED, 
     'Which tab do you want?', 
     array('underline', 'bold') 
    ) 
    ->addOption(
     'description', 
     null, 
     InputOption::VALUE_REQUIRED, 
     'tab dexcription' 
    ) 
    ->addOption(
     'id', 
     null, 
     InputOption::VALUE_REQUIRED, 
     'Which id do you want to delete?', 
     array('4', '5') 
    ); 

    } 

    protected function execute(InputInterface $input, OutputInterface 
    $output) 
    { 
    $paths = array('/var/www/html/silexapp/app/Tnq/Todo/Model/'); 
    $isDevMode = false; 

    // the connection configuration 
    $dbParams = array(
    'driver' => 'pdo_mysql', 
    'user'  => 'root', 
    'password' => 'mysql', 
    'dbname' => 'foo', 
    ); 

    $config= 
    Setup::createAnnotationMetadataConfiguration($paths,$isDevMode); 
    $entityManager = EntityManager::create($dbParams, $config); 

    $tabmodel = new tabmodel\Tab(); 

    if ($input->getOption('create')) { 
     $this->create($input, $output, $tabmodel, $entityManager); 
    } 
    if ($input->getOption('update')) { 
     $this->update($input, $output, $tabmodel, $entityManager); 
    } 
    if ($input->getOption('list')) { 
     $this->listall($input, $output, $tabmodel, $entityManager); 
    } 
    if ($input->getOption('delete')) { 
     $this->delete($input, $output, $tabmodel, $entityManager); 
    } 

} 
protected function create($input, $output, $tabmodel, $entityManager) 
{ 
    $text=''; 
    $tabname = $tabmodel->setTabname($input->getOption('tabname')); 

    $description =  
    $tabmodel->setDescription($input->getOption('description')); 
    $entityManager->persist($tabmodel); 
    $entityManager->flush(); 
    $text .= 'Tab creator'; 
    $text .= 'You are about to '; 
    $text .= 'create a Tab.'; 
    $text .= 'The Tab Id: '.$tabmodel->getId(); 
    $text .= 'The Tab Name: '.$tabmodel->getTabname(); 
    $text .= 'The Tab Description: '.$tabmodel->getDescription(); 
    $output->writeln($text); 
} 
protected function update($input, $output, $tabmodel, $entityManager) 
{ 
    $text=''; 
    $text .= 'Tab Updator : '; 
    $text .= 'You are about to '; 
    $text .= 'update a Tab.'; 
    $text .= 'The id to update: '.$input->getOption('id'); 
    $text .= 'The tabname to update: '.$input->getOption('tabname'); 
    $tab = $entityManager->find('Tab', $input->getOption('id')); 
    if ($tab === null) { 
     $text .= 'The tab id does not exist: '.$input->getOption('id'); 
    } 
    $tab->setName($tabmodel->getTabname()); 
    $entityManager->flush(); 
    $output->writeln($text); 
} 
public function setRepository(TabRepository $repository) 
{ 
    $this->tabRepository = $repository; 

    return $this; 
} 
protected function listall($input, $output, $tabmodel, $entityManager) 
{ 
    $text=''; 
    $tabmodel = new tabmodel\Tab(); 
    $tabRepository = $entityManager->getRepository('Tab'); 
    $tabs = $tabRepository->findAll(); 
    $text .= 'Tab List : '; 
    $text .= 'You are about to '; 
    $text .= 'list a Tab.'; 
    foreach ($tabs as $tab) { 
     $text .= $tab->getName(); 
    } 
    $output->writeln($text); 
} 
protected function delete($input, $output, $tabmodel, $entityManager) 
{ 
    $text=''; 
    $text .= 'Tab Delete : '; 
    $text .= 'You are about to '; 
    $text .= 'delete a Tab.'; 
    $text .= 'The id to delete: '.$input->getOption('id'); 
    $output->writeln($text); 
} 

} 

내 composer.josn 파일 :

{ 
"require": { 
    "silex/silex": "~2.0", 
    "symfony/console": "~3.1", 
    "doctrine/orm": "v2.5.4" 
}, 
"autoload": { 
    "psr-0": { 
     "Cli": "app/", 
     "Tnq\\Todo\\Command": "app/", 
     "Tnq\\Todo\\Service": "app/", 
      "Tnq\\Todo\\Model": "app/" 
     } 
    } 

} 

여기 내 listall getrepository 기능이 오류가 발생합니다. 누구든지 내가이 문제를 찾도록 도와 줄 수 있습니까?

미리 감사드립니다.

답변

3

네임 스페이스 클래스를 getRepository 메소드에 전달해야합니다. 시도 :

$tabRepository = $entityManager->getRepository('Tnq\\Todo\\Model\\Tab'); 
+0

내가 당신이 준 하나를 시도 :이 오류 PHP 치명적인 오류 가지고 : 클래스 'Tnq \ 도도 \ 모델 \ Repository_TabRepository'의/var/www가에서 찾을 수 없습니다/HTML/silexapp/공급 업체/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php on line 68 – malar

+0

내 composer.json 파일도 게시합니다 – malar

+1

예, 작동합니다. 저장소를 제거하고 확인했습니다. 그것은 작동합니다. @gview – malar

관련 문제