Doctrine 2 Cannot find entites

Posted by Flyn San on Stack Overflow See other posts from Stack Overflow or by Flyn San
Published on 2010-12-26T14:49:08Z Indexed on 2010/12/26 14:53 UTC
Read the original article Hit count: 722

Filed under:
|
|
|

I'm using Kohana 3 and have a /doctrine/Entites folder with my entities inside. When executing the code

$product = Doctrine::em()->find('Entities\Product', 1);

in my controller, I get the error

class_parents(): Class Entities\Product does not exist and could not be loaded

Below is the Controller (classes/controller/welcome.php):

<?php

class Controller_Welcome extends Controller {

    public function action_index()
    {
        $prod = Doctrine::em()->find('Entities\Product', 1);
    }

}

Below is the Entity (/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; }
}

Below is the Doctrine module bootstrap file (/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);
    }
}

Any ideas what I've done wrong?

© Stack Overflow or respective owner

Related posts about doctrine

Related posts about kohana