0

これを実行した後、レコードのコレクション ($arrRoleResources) から 5 番目のレコードを読み込む際に問題が発生しました。

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

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

これを実行すると:-

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

5回目の繰り返しで、関連するレコードクラスの1つをエンティティからプロキシに変更します。これはpressntで正しいですが、ロード関数に到達したときにプロキシ(AJFITEntityUserRoleResourcesProxy)をステップスルーした後:-

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);
    }
}

EntityNotFoundException をスローします。

BasicEntityPersister.php の 581 行目で $this->_entityPersister->load() 関数を実行すると:-

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

$entities は null を返しますが、その理由はわかりません。

これが私の構成です:-

    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

私のアプリケーション構成

    [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"

私のブートストラップ:-

 /**
 * 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 = Zend_Registry::getInstance();
    $registry->em = $entityManager;

    return $entityManager;
}

私はこれに数週間取り組んでいるので、誰かが助けてくれませんか。

お時間をいただきありがとうございます

アンドリュー

4

2 に答える 2

0

ご協力いただきありがとうございます。doctrine 2.1.2 と zend 1.11.11 を問題なく接着しました。このエラーを受け取った理由は、関連付けられたエンティティがデータベースで null であり、正しいエラーが発生したためであることがわかりました。

ただし、関連付けられたエンティティがプロキシ クラスであり、そのメソッドが常に null を返すという奇妙な問題が発生しています。私は気が狂ってしまうので、誰かがこの主題に少し光を当ててくれることを願っています.

私はこのコードを呼び出しています:-

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

  foreach($arrRoleResources as $roleResource) {

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

UserRoleResources エンティティ:-

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 エンティティ:-

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;
    }
}

私は zf-boilerplate プリコンパイル済みの例に従いました。必要に応じて構成を投稿できます。ありがとう

:-)

于 2011-10-18T07:23:11.973 に答える
0

あなたの質問に直接答えることはできませんが、私があなただったら、ZF と Doctrine2 に「Bisna」接着剤を使用します: https://github.com/ralphschindler/NOLASnowball

優れたチュートリアル ビデオ: http://www.zendcasts.com/unit-testing-doctrine-2-entities/2011/02/

タイトルはわかりにくいかもしれませんが、ビデオでは ZF と Doctrine2 を統合する方法が非常によく説明されています。

この「接着剤」は私にとって常に完璧に機能し、あなたの問題の解決策にもなると思います.

于 2011-09-30T19:37:03.783 に答える