Php 条令无法映射链中的实体/存储库命名空间
我正在尝试用条令设置symfony,配置条令对我来说是新的 我尝试在控制器中使用以下代码从数据库检索实体:Php 条令无法映射链中的实体/存储库命名空间,php,entity-framework,symfony,doctrine-orm,Php,Entity Framework,Symfony,Doctrine Orm,我正在尝试用条令设置symfony,配置条令对我来说是新的 我尝试在控制器中使用以下代码从数据库检索实体: $feedImport=$this->getDoctrine()->getRepository(MyClass::class) 但我一直得到MappingException错误: 在链配置的命名空间中找不到类“AppBundle\Entity\MyClass” 我还尝试手动指定完全限定的类名。但这没用 然而,从我的角度来看,错误消息似乎建议我需要进行一些额外的配置:我需要将实体/存储库添加
$feedImport=$this->getDoctrine()->getRepository(MyClass::class)代码>
但我一直得到MappingException
错误:
在链配置的命名空间中找不到类“AppBundle\Entity\MyClass”
我还尝试手动指定完全限定的类名。但这没用
然而,从我的角度来看,错误消息似乎建议我需要进行一些额外的配置:我需要将实体/存储库添加到“已配置名称空间链”。但我在找到这个链以及如何配置它时遇到了一些困难(当然,若我的假设是正确的话)
问题#1:是否存在某种名称空间链?如果有,我在哪里可以看到如何配置它的示例
所有实体信息都在myAppBundle
bundle中。请参见下面的捆绑结构:
...
└── AppBundle
├── AppBundle.php
├── Controller
│ └── DefaultController.php
├── Entity
│ └── MyClass.php
├── Repository
│ └── MyClassRepository.php
└── Resources
└── config
└── doctrine
└── MyClass.orm.yml
...
我使用symfonybin\console
工具生成了实体类/repository/orm.yml文件
如果我使用相同的控制台工具检查条令映射信息:
doctrine:mapping:info
命令我向我显示类正确/成功地映射了:
Found 1 mapped entity:
[OK] AppBundle\Entity\MyClass
关于生成模型/实体配置文件的过程。
我使用symfonyconsole
工具生成了元数据yaml文件。通过运行命令:doctrine:mapping:import
。在创建yml文件之后,我使用“条令:生成:实体”来生成enity类
我的印象是,如果生成并存储在实体
文件夹中的工作包中的文件,自动映射:true
将自动处理此映射内容
这个假设正确吗?如果没有,请告诉我出了什么问题
- 实体文件和配置存储在工作包
AppBundle
AppBundle
已注册并工作(控制器正在执行其任务)
- 命令:
doctrine:mapping:info
似乎可以立即映射实体
实体模型的完整代码:
<?php
namespace AppBundle\Entity;
/**
* MyClass
*/
class MyClass
{
/**
* @var integer
*/
private $id;
/**
* @var integer
*/
private $customerId;
/**
* @var integer
*/
private $feedId;
/**
* @var string
*/
private $contentHash;
/**
* @var string
*/
private $headerHash;
/**
* @var string
*/
private $feedName;
/**
* @var integer
*/
private $fileSize;
/**
* @var integer
*/
private $totalHeaderFields;
/**
* @var integer
*/
private $totalRecords;
/**
* @var string
*/
private $importStatus;
/**
* @var \DateTime
*/
private $datetimeCreated = 'CURRENT_TIMESTAMP';
/**
* @var \DateTime
*/
private $datetimeProcessed;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set customerId
*
* @param integer $customerId
*
* @return MyClass
*/
public function setCustomerId($customerId)
{
$this->customerId = $customerId;
return $this;
}
/**
* Get customerId
*
* @return integer
*/
public function getCustomerId()
{
return $this->customerId;
}
/**
* Set feedId
*
* @param integer $feedId
*
* @return MyClass
*/
public function setFeedId($feedId)
{
$this->feedId = $feedId;
return $this;
}
/**
* Get feedId
*
* @return integer
*/
public function getFeedId()
{
return $this->feedId;
}
/**
* Set contentHash
*
* @param string $contentHash
*
* @return MyClass
*/
public function setContentHash($contentHash)
{
$this->contentHash = $contentHash;
return $this;
}
/**
* Get contentHash
*
* @return string
*/
public function getContentHash()
{
return $this->contentHash;
}
/**
* Set headerHash
*
* @param string $headerHash
*
* @return MyClass
*/
public function setHeaderHash($headerHash)
{
$this->headerHash = $headerHash;
return $this;
}
/**
* Get headerHash
*
* @return string
*/
public function getHeaderHash()
{
return $this->headerHash;
}
/**
* Set feedName
*
* @param string $feedName
*
* @return MyClass
*/
public function setFeedName($feedName)
{
$this->feedName = $feedName;
return $this;
}
/**
* Get feedName
*
* @return string
*/
public function getFeedName()
{
return $this->feedName;
}
/**
* Set fileSize
*
* @param integer $fileSize
*
* @return MyClass
*/
public function setFileSize($fileSize)
{
$this->fileSize = $fileSize;
return $this;
}
/**
* Get fileSize
*
* @return integer
*/
public function getFileSize()
{
return $this->fileSize;
}
/**
* Set totalHeaderFields
*
* @param integer $totalHeaderFields
*
* @return MyClass
*/
public function setTotalHeaderFields($totalHeaderFields)
{
$this->totalHeaderFields = $totalHeaderFields;
return $this;
}
/**
* Get totalHeaderFields
*
* @return integer
*/
public function getTotalHeaderFields()
{
return $this->totalHeaderFields;
}
/**
* Set totalRecords
*
* @param integer $totalRecords
*
* @return MyClass
*/
public function setTotalRecords($totalRecords)
{
$this->totalRecords = $totalRecords;
return $this;
}
/**
* Get totalRecords
*
* @return integer
*/
public function getTotalRecords()
{
return $this->totalRecords;
}
/**
* Set importStatus
*
* @param string $importStatus
*
* @return MyClass
*/
public function setImportStatus($importStatus)
{
$this->importStatus = $importStatus;
return $this;
}
/**
* Get importStatus
*
* @return string
*/
public function getImportStatus()
{
return $this->importStatus;
}
/**
* Set datetimeCreated
*
* @param \DateTime $datetimeCreated
*
* @return MyClass
*/
public function setDatetimeCreated($datetimeCreated)
{
$this->datetimeCreated = $datetimeCreated;
return $this;
}
/**
* Get datetimeCreated
*
* @return \DateTime
*/
public function getDatetimeCreated()
{
return $this->datetimeCreated;
}
/**
* Set datetimeProcessed
*
* @param \DateTime $datetimeProcessed
*
* @return MyClass
*/
public function setDatetimeProcessed($datetimeProcessed)
{
$this->datetimeProcessed = $datetimeProcessed;
return $this;
}
/**
* Get datetimeProcessed
*
* @return \DateTime
*/
public function getDatetimeProcessed()
{
return $this->datetimeProcessed;
}
}
试试这个:
$feedImport = $this->getDoctrine()->getRepository('AppBundle:MyClass');
如果要访问特定的函数/方法
$feedImport = $this->getDoctrine()->getRepository('AppBundle:MyClass')->sampleMethod();
试试这个:
$feedImport = $this->getDoctrine()->getRepository('AppBundle:MyClass');
如果要访问特定的函数/方法
$feedImport = $this->getDoctrine()->getRepository('AppBundle:MyClass')->sampleMethod();
您的捆绑包未在AppKernel文件中声明,或者您的条令映射未重新确认
您的AppKernel中应该有:
public function registerBundles()
{
$bundles = array(
...
new AppBundle\AppBundle(),
);
....
return $bundles;
}
默认情况下,在config.yml中:
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
您的捆绑包未在AppKernel文件中声明,或者您的条令映射未重新确认
您的AppKernel中应该有:
public function registerBundles()
{
$bundles = array(
...
new AppBundle\AppBundle(),
);
....
return $bundles;
}
默认情况下,在config.yml中:
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
试试这个:
/**
*
* @ORM\Table(name="my_table_name")
* @ORM\Entity()
*/
class MyClass
试试这个:
/**
*
* @ORM\Table(name="my_table_name")
* @ORM\Entity()
*/
class MyClass
经过长时间的斗争,我发现了问题的起因。
我的symfony环境正在prod
模式下运行。我切换到dev
。这一切都像一种魅力
但我还是想知道为什么?!我检查了AppKernel.php
,它看起来像:
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}
return $bundles;
在我看来,无论我在什么样的环境下运行,原则都会被加载。谁能给我解释一下这种行为背后的原因吗
编辑:
我发现了更多的东西,我再次切换到prod
环境,但现在我开始打开/关闭调试
现在我看到它在生产模式下工作得很好,但只有在启用调试的情况下。为什么? 经过长时间的斗争,我发现了问题的根源。
我的symfony环境正在prod
模式下运行。我切换到dev
。这一切都像一种魅力
但我还是想知道为什么?!我检查了AppKernel.php
,它看起来像:
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}
return $bundles;
在我看来,无论我在什么样的环境下运行,原则都会被加载。谁能给我解释一下这种行为背后的原因吗
编辑:
我发现了更多的东西,我再次切换到prod
环境,但现在我开始打开/关闭调试
现在我看到它在生产模式下工作得很好,但只有在启用调试的情况下。为什么? 你的PHP版本是什么?我的服务器正在运行PHP7.1你能显示你的实体
类和命名空间
?这是我的实体类:文件路径:MyProject/src/AppBundle/Entity/MyClass.PHP
`我想看看你的实体
类所有代码你的PHP版本是什么?我的服务器正在运行PHP7.1你能显示吗您的实体
类和名称空间
?这是我的实体类:文件路径:MyProject/src/AppBundle/Entity/MyClass.php
`我想看看您的实体
类所有代码抱歉,我忘了提到我已经尝试了AppBundle:MyClass
语法。也不起作用。对不起,我忘了提到我已经尝试了AppBundle:MyClass
语法。然后php-bin/console-doctor:schema:update--force
我按照您描述的方式添加了doc块,并运行doctor:schema:update--force
命令。命令执行正常。但还是同样的错误…:(然后php-bin/console-doctor:schema:update--force
我按照您描述的方式添加了doc块,并运行了doctor:schema:update--force
命令。命令执行正常。但仍然是相同的错误…:(我检查了AppKernel.php
和我的config.yml
以查看这些设置。它像您描述的那样都已就绪。我检查了AppKernel.php
和我的config.yml
以查看这些设置。它像您描述的那样已就绪。