Welcome Guest, Not a member yet? Register   Sign In
CI2 And Doctrine2 EntityRepository Problem
#1

[eluser]Unknown[/eluser]
First, Sorry for my english... LOL.

Second, The problem...

What I want? Use a simple reposotory.

What I’ve tried?
I made 3 classes (User class, Client class extends of User and UserRepository)

[/b]Here is the directory structure:[/b]
models (Folder)
--> User.php (Class)
--> Client.php (Class)
--> repositories (Folder) --> UserRepository.php (Class)

The Classes

User.php (CONSCIOUS Remove the getters and setter method)

Code:
namespace models;

use DoctrineCommonCollectionsArrayCollection;

/**
* @Entity
* @Table(name="usuarios")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="tipo_usuario", type="string")
* @DiscriminatorMap({"user" = "User", "ROLE_CLIENTE" = "Cliente"})
* @entity(repositoryClass="models\\repositories\\UserRepository")
*/
class User
{
  

    /**
     * @Id
     * @Column(type="integer", nullable=false)
     * @GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @Column(type="string", length=32, nullable=false)
     */
    protected $username;

    /**
     * @Column(type="string", length=64, nullable=false)
     */
    protected $password;

    /**
     * @Column(type="string", length=255, nullable=false)
     */
    protected $email;


}

UserRepository.php
Code:
<?php
namespace modelsrepositories;
use DoctrineORMEntityRepository;

class UserRepository extends EntityRepository {
        
    function validate(){
        
        $em = $this->getEntityManager();
        $em->createQuery('SELECT u FROM models\User u WHERE u.username = "Cliente"')
           ->getResult();
    }
}
?>

The call in the Controller

Code:
$em = $this->doctrine->em;
        $user = $em->getRepository('models\repositories\UserRepository')
                   ->validate();

The file doctrine.php
Code:
<?php
use DoctrineORMEntityManager,
    DoctrineORMConfiguration;

define('DEBUGGING', FALSE);

class Doctrine {

    public $em = null;

    public function __construct()
    {
        // load database configuration and custom config from CodeIgniter
        require APPPATH . 'config/database.php';

        // Set up class loading.
        require_once APPPATH . 'libraries/Doctrine/Common/ClassLoader.php';

        $doctrineClassLoader = new DoctrineCommonClassLoader('Doctrine', APPPATH . 'libraries');
        $doctrineClassLoader->register();

        $entitiesClassLoader = new DoctrineCommonClassLoader('models', rtrim(APPPATH, '/'));
        $entitiesClassLoader->register();

        $proxiesClassLoader = new DoctrineCommonClassLoader('Proxies', APPPATH . 'models');
        $proxiesClassLoader->register();

        $symfonyClassLoader = new DoctrineCommonClassLoader('Symfony', APPPATH . 'libraries/Doctrine');
        $symfonyClassLoader->register();
//                $entityClassLoader = new \Doctrine\Common\ClassLoader('repositories', APPPATH.'models');
//                $entityClassLoader->register();

        // Choose caching method based on application mode
        if (ENVIRONMENT == 'production')
        {
            $cache = new DoctrineCommonCacheApcCache;
        }
        else
        {
            $cache = new DoctrineCommonCacheArrayCache;
        }

        // Set some configuration options
        $config = new Configuration;

        // Metadata driver
        $driverImpl = $config->newDefaultAnnotationDriver(APPPATH . 'models');    
        $config->setMetadataDriverImpl($driverImpl);

        // Caching
        $config->setMetadataCacheImpl($cache);
        $config->setQueryCacheImpl($cache);

        // Proxies
        $config->setProxyDir(APPPATH . 'models/Proxies');
        $config->setProxyNamespace('Proxies');

        if (ENVIRONMENT == 'development') {
            $config->setAutoGenerateProxyClasses(TRUE);
        } else {
            $config->setAutoGenerateProxyClasses(FALSE);
        }

        // SQL query logger
        if (DEBUGGING)
        {
            $logger = new DoctrineDBALLoggingEchoSQLLogger;
            $config->setSQLLogger($logger);
        }

        // Database connection information
        $connectionOptions = array(
            'driver' => 'pdo_mysql',
            'user' => $db['default']['username'],
            'password' => $db['default']['password'],
            'host' => $db['default']['hostname'],
            'dbname' => $db['default']['database']
        );

        // Create EntityManager
        $this->em = EntityManager::create($connectionOptions, $config);
    }
}

Quote:The comment lines down of the 'Symfony' was a possible solution, obviously don´t work

The Error

Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class models\repositories\UserRepository is not a valid entity or mapped super class.' in ..\htdocs\DoCI\application\libraries\Doctrine\ORM\ Mapping\MappingException.php:142 Stack trace: #0 htdocs\DoCI\application\libraries\Doctrine\ORM\Map ping\Driver\AnnotationDriver.php(148): Doctrine\ORM\Mapping\MappingException::classIsNotA ValidEntityOrMappedSuperClass('models\reposito...' ) #1 ..\htdocs\DoCI\application\libraries\Doctrine\ORM\ Mapping\ClassMetadataFactory.php(281): Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('models\reposito...', Object(Doctrine\ORM\Mapping\ClassMetadata)) #2 ..\htdocs\DoCI\application\libraries\Doctrine\ORM\ Mapping\ClassMetadataFactory.php(170): Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata('models\reposito...') #3 ..\htdocs\DoCI\application\libraries\Doctrine\ORM\ EntityManager.php(257): Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor('models\ in ..\htdocs\DoCI\application\libraries\Doctrine\ORM\

Thanks for read my post!!!

Nico.
#2

[eluser]stcoid1[/eluser]
hi,
i will help you,
can you publish your full source code + url link website ?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB