2
votes

i've tried to integrate the Gedmo Translatable Extension in Doctrine 2.2/Zend, but I didn't succeed and need some help. I'm always getting this fatal error:

Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class AliasStaticPage is not a valid entity or mapped super class.' in[...]library/Doctrine/ORM/Mapping/MappingException.php:147

APC is running, Doctrine 2.2 worked also fine (before).

This is my Bootstrap (similar to Best practices for setting up with annotations):

    $cache = new \Doctrine\Common\Cache\ApcCache();      
    $config->setQueryCacheImpl($cache);
    $config->setResultCacheImpl($cache);
    $config->setMetadataCacheImpl($cache);

    $config->setProxyNamespace('App\Proxies');

    $annotationReader = new Doctrine\Common\Annotations\AnnotationReader();

    Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
        'Gedmo\Mapping\Annotation',
        '../library/DoctrineExtensions/Gedmo'
    );
    Doctrine\Common\Annotations\AnnotationRegistry::registerFile(
        '../library/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'
    );

    $chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain();    
    $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($annotationReader,
            array(
            APPLICATION_PATH . '/models',
            '../library/DoctrineExtensions/Gedmo/Translatable/Entity'
            ));
    $chainDriverImpl->addDriver($annotationDriver, 'Entity');
    $chainDriverImpl->addDriver($annotationDriver, 'Gedmo\Translatable\Entity');

    $config->setMetaDataDriverImpl($chainDriverImpl);

and here are parts of the class definition:

<?php
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="alias")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorMap({"aliasProject" = "AliasProject",                    
 *                    "aliasStaticPage" = "AliasStaticPage"})
 */
abstract class Alias 
{
/**
 * @Id 
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;
[...] 
}

And the joined class:

<?php 
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="aliasStaticPage")
 */
class AliasStaticPage extends Alias
{

/**
 * @ManyToOne(targetEntity="StaticPage")
 * @JoinColumns({@JoinColumn(name="staticPage_id", referencedColumnName="id")})
 */
private $staticPage;
[...]
}

I've also tried this approach on doctrine-project.org without success...

Many thanks for any ideas.

1
Solve it.. but can't answer my solution not until 4 hours.. - theColaKid

1 Answers

0
votes

So here's my solution:

Implementing the AnnotationDriver this way led within \Doctrine\ORM\Mapping\Driver\DriverChain in line 93 to the same object hash.. don't know why, but it looped only once. So i split it in 2 annotationDrivers, one for my models and one for the Gedmo Entities:

$annotationReader = new Doctrine\Common\Annotations\AnnotationReader();
$annotationDriver1 = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($annotationReader, array('../library/DoctrineExtensions/Gedmo/Translatable/Entity'));
$annotationDriver2 = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($annotationReader, array(APPLICATION_PATH . '/models'));

$chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain();
$chainDriverImpl->addDriver($annotationDriver1, 'Gedmo\Translatable\Entity');
$chainDriverImpl->addDriver($annotationDriver2, 'Model');

Next the namespace of the added driver was not conform to my namespace, that's way it never ended up looking into the classes. I also had to add the prefix @ORM\ to all ManyToOne, Join ...

And that was it. Hope this can help somebody else in the same situation.