Class does not exist in getRepository doctrine(getRepository规则中不存在类)
本文介绍了getRepository规则中不存在类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对教义和交响乐是新手。我已经创建了一个小的应用程序与凝乳操作使用法则ORM。我的插入操作正在工作,但我的列表操作引发错误,原因是
[DoctrineCommonPersistenceMappingMappingException]
我将在此处粘贴代码:
我的型号file:/var/www/html/silexapp/app/Tnq/Todo/Model/Tab.php
类"Tab"不存在
<?php
namespace TnqTodoModel;
// 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;
}
}
我的Doctrine ORM文件,我在其中执行curd操作:
/var/www/html/silexapp/app/Tnq/Todo/Command/Tabcommand.php
<?php
namespace TnqTodoCommand;
require_once "../vendor/autoload.php";
//require_once '/var/www/html/silexapp/app/web/bootstrap.php';
use TnqTodoModel as tabmodel;
use DoctrineORMToolsSetup;
use DoctrineORMEntityManager;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use SymfonyComponentConsoleInputInputArgument;
use SymfonyComponentConsoleInputInputOption;
use SymfonyComponentConsoleInputInputDefinition;
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 tabmodelTab();
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 tabmodelTab();
$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 getpository函数抛出错误。
有人能帮我找出问题所在吗?
提前谢谢您。
推荐答案
您需要将命名空间类传递给getRepository方法。尝试:
$tabRepository = $entityManager->getRepository('Tnq\Todo\Model\Tab');
这篇关于getRepository规则中不存在类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:getRepository规则中不存在类
基础教程推荐
猜你喜欢
- 在多维数组中查找最大值 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01