开发者

zend 1.11 doctrine2.1.1 - EntityNotFoundException entity was not found

I'm having problems loading the 5th record from my collection ($arrRoleResources) of records, after I run this, which works fine:-

    $em = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('doctrine');

    $arrRoleResources = $em->getRepository("AJFIT\Entities\UserRoleResources")->findAll();

When I run through this :-

    foreach($arrRoleResources as $roleResource) {
        self::$_objAcl->allow($roleResource->getRoleFk()->getName(),$roleResource->getResourcesFk()->getModule() . '::' . $roleResource->getResourcesFk()->getController() . '::' . $roleResource->getResourcesFk()->getAction());  
    }

On the 5th iteration it changes one of the related records class from an entity to a proxy which is pressnt and correct, however after stepping through the proxy (AJFITEntityUserRoleResourcesProxy) when it gets to the load function:-

private function _load()
{
    if (!$this->__isInitialized__ && $this->_entityPersister) {
        $this->__isInitialized__ = true;
        if ($this->_entityPersister->load($this->_identifier, $this) === null) {
            throw new \Doctrine\ORM\EntityNotFoundException();
        }
        unset($this->_entityPersister, $this->_identifier);
    }
}

It throws the EntityNotFoundException.

When I step through the $this->_entityPersister->load() function with in BasicEntityPersister.php on line 581:-

    $entities = $hydrator->hydrateAll($stmt, $this->_rsm, $hints);

$entities returns null, and i am unsure why.

Here is my configuration:-

    Root
    |-----application
    |-----library
            |-----AJFIT
            |       |-----Entities (namespaces = AJFIT\Entities)
            |       |        |-----UserResources.php
            |       |        |-----UserRoleResources.php
            |       |        |-----UserRoles.php
            |       |-----Proxies  (namespaces = AJFIT\Proxies) <-auto generated
            |                |-----AJFITEntitiesUserResources.php
            |                |-----AJFITEntitiesUserRoleResources.php
            |                |-----AJFITEntitiesUserRoles.php
            |-----Doctrine
            |-----Zend
            |-----ZendX

My Application configuration

    [production]    

    autoloadernamespaces[] = "AJFIT"
    autoloadernamespaces[] = "Doctrine"

    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1

    includePaths.library = APPLICATION_PATH "/../library"

    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"

    resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
    resources.frontController.params.displayExceptions = 1
    resources.frontController.baseurl = "/"

    resources.layout.layout = "layout"
    resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"

    resources.view.encoding = "UTF-8"
    resources.view.basePath = APPLICATION_PATH "/views/"

    ; ------------------------------------------------------------------------------
    ; Doctrine Database Configuration
    ; ------------------------------------------------------------------------------

    doctrine.conn.host = '127.0.0.1'
    doctrine.conn.user = 'ajfit'
    doctrine.conn.pass = '*****'
    doctrine.conn.driv = 'pdo_mysql'
    doctrine.conn.dbname = 'ajfit'
    doctrine.path.entities = APPLICATION_PATH "../../library/AJFIT/Entities"

My Bootstrap:-

 /**
 * Register namespace Default_
 * @return Zend_Application_Module_Autoloader
 */
protected function _initAutoload()
{
    $autoloader = new \Doctrine\Common\ClassLoader('Zend');
    $autoloader->setNamespaceSeparator('_'); 
    $autoloader->register(); 

    return $autoloader;
}

/**
 * Initialize Doctrine
 * @return Doctrine_Manager
 */
public function _initDoctrine() {
    $this->bootstrap('autoload'); 

    // include and register Doctrine's class loader
    require_once(APPLICATION_PATH . '/../library/Doctrine/Common/ClassLoader.php');

    $classLoader = new \Doctrine\Common\ClassLoader(
        'Doctrine', 
        APPLICATION_PATH . '/../library/Doctrine'
    );
    $classLoader->register();

    $classLoader = new \Doctrine\Common\ClassLoader(
        'Symfony', 
        APPLICATION_PATH . '/../library/Doctrine/Symfony'
    );
    $classLoader->register();

    $classLoader = new \Doctrine\Common\ClassLoader(
        'AJFIT', 
        APPLICATION_PATH . '/../library/AJFIT/'
    );
    $classLoader->register();

    // create the Doctrine configuration
    $config = new \Doctrine\ORM\Configuration();

    // setting the cache ( to ArrayCache. Take a look at
    // the Doctrine manual for different options ! )
    $cache = new \Doctrine\Common\Cache\ArrayCache;
    //$cache = new \Doctrine\Common\Cache\ApcCache;
    $config->setMetadataCacheImpl($cache);
    $config->setQueryCacheImpl($cache);

    // choosing the driver for our database schema
    // we'll use annotations

    $driver = $config->newDefaultAnnotationDriver(
        APPLICATION_PATH . '/../library/AJFIT/Entities'
    );

    //$driver = new Doctrine\ORM\Mapping\Driver\XmlDriver(
    //        APPLICATION_PATH . '/../library/AJFIT/Mappings/XML');

    //$driver = new Doctrine\ORM\Mapping\Driver\YamlDriver(
    //        APPLICATION_PATH . '/../library/AJFIT/Mappings/YML');

    $config->setMetadataDriverImpl($driver);

    // set the proxy dir and set some options
    $config->setProxyDir(APPLICATION_PATH . '/../library/AJFIT/Proxies');
    $config->setAutoGenerateProxyClasses(true); 
    $config->setProxyNamespace('AJFIT\Proxies');

    // now create the entity manager and use the connection
    // settings we defined in our application.ini
    $connectionSettings = $this->getOption('doctrine');
    $conn = array(
        'driver'    => $connectionSettings['conn']['driv'],
        'user'      => $connectionSettings['conn']['user'],
        'password'  => $connectionSettings['conn']['pass'],
        'dbname'    => $connectionSettings['conn']['dbname'],
        'host'      => $connectionSettings['conn']['host']
    );
    $entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);

    // push the entity manager into our registry for later use
    $registry = Ze开发者_StackOverflownd_Registry::getInstance();
    $registry->em = $entityManager;

    return $entityManager;
}

Please can someone help as I have been working on this for a few weeks now and i don't seem to be getting anywhere with it.

Thank-you for your time

Andrew


It does not directly answer your question but if I was you I would use the 'Bisna' glue for ZF and Doctrine2: https://github.com/ralphschindler/NOLASnowball

For a good tutorial video: http://www.zendcasts.com/unit-testing-doctrine-2-entities/2011/02/

The title might sound confusing but the video explains very well how to intergrate ZF and Doctrine2.

This 'glue' worked always perfectly for me and I think it might be a solution to your problem as well.


Thanks for your help, i have already glued doctrine 2.1.2 and zend 1.11.11 with no issues, and i found out the reason that i was recieving this error was due to the associated entity being null in the database causing the correct error.

However I am having this strange issue with an assoiative entity being a proxy class and its methods always returning null. I hope someone can shed a little light on the subject because iuts driving me insane.

i am calling this code:-

  $arrRoleResources = $em->getRepository("AJFIT\Entity\UserRoleResources")->findAll();

  foreach($arrRoleResources as $roleResource) {

         $name = $roleResource->getRoleFk()->getName();
  }

UserRoleResources Entity:-

namespace AJFIT\Entity;

/**
* UserRoleResources
*
* @Table(name="user_role_resources")
* * @Entity(repositoryClass="AJFIT\Repository\UserRoleResources")
*/
class UserRoleResources
{

   /**
   * @var UserRoles
   *
   * @ManyToOne(targetEntity="UserRoles")
   * @JoinColumn(name="role_fk", referencedColumnName="pk")
   * 
   */

   private $roleFk;

   /**
   * Get roleFk
   *
   * @return UserRoles $roleFk
   */

   public function getRoleFk()
   {
       return $this->roleFk;
   }
}

UserRole Entity:-

namespace AJFIT\Entity;

/**
 * UserRoles
 *
 * @Table(name="user_roles")
 * * @Entity(repositoryClass="AJFIT\Repository\UserRoles")
 */
class UserRoles
{
    /**
    * @var string $name
    *
    * @Column(name="name", type="string", length=255)
    */
    private $name;

    /**
    * @var integer $pk
    *
    * @Column(name="pk", type="integer")
    * @Id
    * @GeneratedValue(strategy="IDENTITY")
    */
    private $pk;

    /**
    * Get name
    *
    * @return string $name
    */
    public function getName()
    {
        return $this->name;
    }
}

I have followed the zf-boilerplate precompiled example, and i am able to post my config if required. Thanks

:-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜