实体命名空间子类在Doctrine中不起作用


Entity namespace subclass not working in Doctrine

我在Composer中使用Doctrine。

我在基类上有以下代码:

Entidades'BaseTable.php...
<?php
use Doctrine'Common'Collections'ArrayCollection;
/**
 * @MappedSuperclass
 */
class BaseTable
{
    /**
     * @Id @Column(type="integer", nullable=false)
     * @GeneratedValue(strategy="IDENTITY")
     */
    protected $id;
    /**
     * @Column(type="datetime")
     * @var datetime
     */
    protected $criado_em;
    public function __construct()
    {
        date_default_timezone_set('Australia/Melbourne');
        $this->criado_em = new DateTime(null, new DateTimeZone('America/Sao_Paulo'));
    }
    public function getId()
    {
        return $this->id;
    }
}
?>

在最后一节课上,我得到了:

Entidades'Sistema'Aplicativo.php...
<?php
use Doctrine'Common'Collections'ArrayCollection;
namespace Entidades'Sistema;
/**
 * @Entity @Table(name="sistema.aplicativos")
 */
class Aplicativo Extends 'Entidades'BaseTable
{
    /**
     * @Column(type="string", nullable=false)
     * @var string
     */
    public $nome;
    /**
     * @Column(type="string", unique=true, nullable=false)
     * @var string
     */
    public $app_key;
    /**
     * @Column(type="string", unique=true, nullable=false)
     * @var string
     */
    public $esquema;
    public function addAplicativo($nome,$esquema)
    {
        $this->nome = $nome;
        $this->esquema = $esquema;
    }
    protected function newGuid()
    {
        if (function_exists('com_create_guid') === true)
        {
            return trim(com_create_guid(), '{}');
        }
        return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0,     65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
    }
    public function __construct()
    {
        parent::__construct();
        $this->app_key = newGuid();
    }
}
?>

当我在项目根上使用命令php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create时,它会创建所有良好的东西。但当我做一些类似的事情时:

<?php
require_once "bootstrap.php";
$novo = new Sistema'Aplicativo();
$novo->nome = 'Teste';
$novo->esquema = 'Teste';
$entityManager->persist($novo);
$entityManager->flush();
echo "Aplicativo com o ID " . $product->getId() . " criado com sucesso.'n";
?>

PHP抛出一个错误,如:

Fatal error: Class 'Entidades'BaseTable' not found in PROJECTPATH'Entidades'Sistema'Aplicativo.php on line 10
Call Stack
#   Time    Memory  Function    Location
1   0.0006  127464  {main}( )   ..'addAplicativo.php:0
2   0.0775  2090656 Composer'Autoload'ClassLoader->loadClass( ) ..'addAplicativo.php:0
3   0.0775  2090760 Composer'Autoload'includeFile( )    ..'ClassLoader.php:274
4   0.0782  2098408 include( 'D:'TRABALHO'Admin v3'Server'Entidades'Sistema'Aplicativo.php' )           ..'ClassLoader.php:382

已解决

问题是作曲家自动加载。。。

我在那里犯了一个错误,解决方案是放入自动加载,psd-4带有名称空间,psr-0没有按规定工作。。。但是psr-4是的。。。

"autoload": {
    "psr-4": {
        "": "Entidades/",
        "Entidades''": "Entidades/",
        "Entidades''Sistema''": "Entidades/Sistema/"
    }
}

tnx为你的时间。