我正在使用 Kohana 3 并有一个 /doctrine/Entites 文件夹,里面有我的实体。执行代码时
$product = Doctrine::em()->find('Entities\Product', 1);
在我的控制器中,我得到了错误
class_parents(): Class Entities\Product does not exist and could not be loaded
下面是控制器(classes/controller/welcome.php):
<?php
class Controller_Welcome extends Controller {
public function action_index()
{
$prod = Doctrine::em()->find('Entities\Product', 1);
}
}
下面是实体(/doctrine/Entities/Product.php):
<?php
/**
* @Entity
* @Table{name="products"}
*/
class Product
{
/** @Id @Column{type="integer"} */
private $id;
/** @Column(type="string", length="255") */
private $name;
public function getId() { return $this->id; }
public function setId($id) { $this->id = intval($id); }
public function getName() { return $this->name; }
public function setName($name) { $this->name = $name; }
}
下面是 Doctrine 模块引导文件(/modules/doctrine/init.php):
class Doctrine
{
private static $_instance = null;
private $_application_mode = 'development';
private $_em = null;
public static function em()
{
if ( self::$_instance === null )
self::$_instance = new Doctrine();
return self::$_instance->_em;
}
public function __construct()
{
require __DIR__.'/classes/doctrine/Doctrine/Common/ClassLoader.php';
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', __DIR__.'/classes/doctrine');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', __DIR__.'/classes/doctrine/Doctrine');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Entities', APPPATH.'doctrine');
$classLoader->register();
//Set up caching method
$cache = $this->_application_mode == 'development'
? new \Doctrine\Common\Cache\ArrayCache
: new \Doctrine\Common\Cache\ApcCache;
$config = new Configuration;
$config->setMetadataCacheImpl( $cache );
$driver = $config->newDefaultAnnotationDriver( APPPATH.'doctrine/Entities' );
$config->setMetadataDriverImpl( $driver );
$config->setQueryCacheImpl( $cache );
$config->setProxyDir( APPPATH.'doctrine/Proxies' );
$config->setProxyNamespace('Proxies');
$config->setAutoGenerateProxyClasses( $this->_application_mode == 'development' );
$dbconf = Kohana::config('database');
$dbconf = reset($dbconf); //Use the first database specified in the config
$this->_em = EntityManager::create(array(
'dbname' => $dbconf['connection']['database'],
'user' => $dbconf['connection']['username'],
'password' => $dbconf['connection']['password'],
'host' => $dbconf['connection']['hostname'],
'driver' => 'pdo_mysql',
), $config);
}
}
任何想法我做错了什么?