我对 Doctrine2 很陌生,并且正在尝试设置自定义存储库,但是我遇到了一个错误,我似乎无法通过谷歌搜索:
这是实体:
// entities/Customer.php
namespace Entities;
/** @Entity (repositoryClass="Repositories\CustomerRepository")
* @Table (name="customer") */
class Customer { /* ... */ }
这是存储库:
// repositories/CustomerRepository.php
namespace Repositories;
use Doctrine\ORM\EntityRepository;
class CustomerRepository extends EntityRepository {
public function getAllEnterprises() {
return $this->_em->createQuery(
'SELECT c FROM Customer c WHERE column_x IS NOT NULL')->getResult();
}
}
PHP 冲我大喊:
PHP 致命错误:无法在第 10 行的实体/Customer.php 中重新声明类 Entities\Customer
PHP 5.4.6,通过作曲家安装的学说。
引导程序.php:
// bootstrap.php
if (!class_exists('Doctrine\Common\Version', false)) {
require_once "bootstrap_doctrine.php";
}
require_once "entities/Customer.php";
require_once "repositories/CustomerRepository.php";
require_once "entities/Location.php";
bootstrap_doctrine.php
// bootstrap_doctrine.php
use Doctrine\ORM\Tools\Setup;
require_once "vendor/autoload.php";
// Create a simple "default" Doctrine ORM configuration
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(
array(__DIR__."/entities"), $isDevMode);
// database configuration parameters
$conn = array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'someuser',
'password' => 'somepassword',
'dbname' => 'somename',
'unix_socket' => '/var/run/mysqld/mysqld.sock',
);
// obtaining the entity manager
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
我究竟做错了什么?