Zend 1.11.11原则2.1.2关联代理实体的初步化 [英] Zend 1.11.11 Doctrine 2.1.2 initalising of associative proxy entities

查看:134
本文介绍了Zend 1.11.11原则2.1.2关联代理实体的初步化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,一个关联实体是一个代理类,它的方法总是返回null。我希望有人可以对这个问题做一点点光,因为它让我疯狂。

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

我打电话给这个代码: -

i am calling this code:-

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

foreach($arrRoleResources as $roleResource) {
       $name = $roleResource->getRoleFk()->getName();   
} 

即使调试代码初始化时,$ name始终为空代理类和$ _identifier具有正确的主键。

The $name will always be null even though when I debug the code it initializes the proxy class and the $_identifier is with the correct primary key.

UserRoleResources实体: -

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实体: -

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

我已经遵循了zf样板预编译的例子,如果需要,我可以发布我的配置。谢谢

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

: - )

推荐答案

小错了尝试修复这些...

Some of your annotations look a little wrong. Try fixing these up...

丢失额外的星号。

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



属性注释



将文档块直接置于属性上方(无空行)

Property annotation

Place the docblocks directly above the properties (no blank lines)

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

这篇关于Zend 1.11.11原则2.1.2关联代理实体的初步化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆