doctrine-orm - 教义找不到实体
问题描述
models
Doctrine 在项目文件夹中找不到我的实体。
测试文件:
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array("models"), $isDevMode);
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => '',
'password' => '',
'dbname' => '',
);
$entityManager = EntityManager::create($dbParams, $config);
try {
/** @var \models\Vars $repo */
$repo = $entityManager->getRepository('Vars');
echo 'success';
} catch (Exception $e) {
echo $e->getMessage();
}
模型/变量:
<?php
namespace models;
use Doctrine\ORM\Annotation as ORM;
/**
* @ORM\Entity(name="Vars")
* @ORM\Table(name="vars")
*/
class Vars
{
}
我是 php 的新手。总之感谢。
解决方案
解决了。我只是从实体中删除命名空间,现在一切正常。但这是正确的解决方案吗?
推荐阅读
- moodle-mobile - 在moodle移动应用程序中复制课程内容或文件
- excel - 通过 reg 文件添加可信文件 excel
- terraform - terraform-compliance 步骤未区分计划中的资源
- c# - 如果它们存储在列表中,CodeEffects RuleEditor 不会显示枚举值
- firebase - Firebase 身份验证无法正常工作
- date - Qlik - 创建计算维度以显示从月份开始到过滤日期的条形图(5-4-4 日历)
- flutter - sdkmanager.bat 文件被自动删除
- angular - 使用 Karma 进行单元测试,Jasmine 在基于接口的依赖注入中面临问题
- google-chrome - Chrome上的Firefox contextualIndetities(容器)?
- git - 恢复到不属于任何分支的提交