作爲一個學說2.1新手我想開始使用學說2,但我堅持什麼似乎基本的東西。但我仍不能環繞它我的頭:學說2的配置問題,似乎無法找到實體
運行
$ doctrine orm:generate-entities Entities
Processing entity "MyUser"
Entity classes generated to "/home/lucvh/NetBeansProjects/doctrinetest/Entities"
生成什麼MyUser.php文件我希望(見下文)
我然後繼續生成模式這顯然是因爲類加載器不工作,因爲它似乎沒有找到位於實體目錄下的MyUser類。我在想什麼.....
$ doctrine orm:schema-tool:create
PHP Warning: class_parents(): Class MyUser does not exist and could not be loaded in /usr/share/php/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 223
PHP Warning: array_reverse() expects parameter 1 to be array, boolean given in /usr/share/php/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 223
PHP Warning: Invalid argument supplied for foreach() in /usr/share/php/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 223
[ReflectionException]
Class MyUser does not exist
orm:schema-tool:create [--dump-sql]
MyUser.php:
配置的<?php
use Doctrine\ORM\Mapping as ORM;
/**
* MyUser
*/
class MyUser
{
/**
* @var string $Firstname
*/
private $Firstname;
/**
* @var string $Lastname
*/
private $Lastname;
/**
* @var string $Email
*/
private $Email;
/**
* @var boolean $Enabled
*/
private $Enabled;
/**
* @var integer $Id
*/
private $Id;
/**
* Set Firstname
*
* @param string $firstname
*/
public function setFirstname($firstname)
{
$this->Firstname = $firstname;
}
/**
* Get Firstname
*
* @return string
*/
public function getFirstname()
{
return $this->Firstname;
}
/**
* Set Lastname
*
* @param string $lastname
*/
public function setLastname($lastname)
{
$this->Lastname = $lastname;
}
/**
* Get Lastname
*
* @return string
*/
public function getLastname()
{
return $this->Lastname;
}
/**
* Set Email
*
* @param string $email
*/
public function setEmail($email)
{
$this->Email = $email;
}
/**
* Get Email
*
* @return string
*/
public function getEmail()
{
return $this->Email;
}
/**
* Set Enabled
*
* @param boolean $enabled
*/
public function setEnabled($enabled)
{
$this->Enabled = $enabled;
}
/**
* Get Enabled
*
* @return boolean
*/
public function getEnabled()
{
return $this->Enabled;
}
/**
* Get Id
*
* @return integer
*/
public function getId()
{
return $this->Id;
}
}
內容/映射/ XML/MyUser.dcm.xml
<?xml version="1.0"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="MyUser">
<id name="Id" type="integer">
<generator strategy="AUTO"/>
</id>
<field name="Firstname" type="string" nullable="true"/>
<field name="Lastname" type="string" nullable="true"/>
<field name="Email" type="string" nullable="true"/>
<field name="Enabled" type="boolean" nullable="true"/>
</entity>
</doctrine-mapping>
CLI的內容-config.php
<?php
require_once '/usr/share/php/Doctrine/Common/ClassLoader.php';
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(__DIR__."/config/mappings/xml");
$config->setMetadataDriverImpl($driverImpl);
$connectionOptions = array(
'driver' => 'pdo_pgsql',
'host' => 'localhost',
'user' => 'xxx',
'password' => 'xxx',
'dbname' => 'xx'
);
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
?>
應該在哪裏添加這個命名空間/什麼是缺少的命名空間? – Shawn