首页 > 解决方案 > 教义找不到实体

问题描述

modelsDoctrine 在项目文件夹中找不到我的实体。

测试文件:

<?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 的新手。总之感谢。

标签: doctrine-orm

解决方案


解决了。我只是从实体中删除命名空间,现在一切正常。但这是正确的解决方案吗?


推荐阅读