2
我正在使用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