2011-07-08 44 views
2

我正在使用Doctrine 2和Zend Framework 1.11。我已經建立了我的學說集成體系,並且它在接下來的工作中,我能夠獲得實例經理的實例並與之合作。但是,我通過在控制器類以下行的行爲感到困惑:學說2查詢返回的對象沒有屬性或方法

$transfercurrency = $this->entityManager->getRepository('Gesmoney\Entity\Country')->findBy(array('countrycode' => $transfercountry)); 

當我做的var_dump($ transfercurrency),我得到了一大堆屬性的對象,事實上,這不是」你看我是對的。我試圖將它張貼在pastie上,但它不會讓我因爲它超過100kb。因此,我只是粘貼了大約四分之一enter link description here。同樣使用Netbeans,似乎沒有返回對象的屬性或方法,因此當我調用代碼完成時,我什麼也得不到。當我做var_dump($ transfercurrency [0] - > id)時,我得到以下錯誤;

公告:未定義的屬性: Gesmoney \實體\國家::在線55 NULL在 /shared/www/dev.gesmoneylatest.com/library/Gesmoney/Entity/Country.php $財產

這是一個相當長的帖子,但我希望有人對我的問題有答案。謝謝。

Controller類

<?php 

class Systemadmin_ExchangerateController extends Zend_Controller_Action 
{ 
/** 
* @var Bisna\Application\Container\DoctrineContainer 
*/ 
protected $doctrine; 

/** 
* @var Doctrine\ORM\EntityManager 
*/ 
protected $entityManager; 

public function init() 
{ 
    $this->doctrine = Zend_Registry::get('doctrine'); 
    $this->entityManager = $this->doctrine->getEntityManager(); 
} 

public function indexAction() 
{ 
    // action body 
} 


public function getexchangerateAction($transfercountry = 'GB') { 

    $this->_helper->layout()->disableLayout(); 
    $this->_helper->viewRenderer->setNoRender(true); 

    $transfercurrency = $this->entityManager->getRepository('Gesmoney\Entity  \Country')->findBy(array('countrycode' => $transfercountry)); 
    var_dump($transfercurrency); 
} 

} 

實體

<?php 

namespace Gesmoney\Entity; 
/** 
* @Entity @Table(name="countries") 
*/ 
class Country { 
/** 
* @Id @Column(type="integer", length=3, nullable=false) 
* @GeneratedValue(strategy="IDENTITY") 
* @var integer 
* 
*/ 
private $id; 

/** 
* @Column(type="string", length=25) 
* @var string 
*/ 
private $countryname; 

/** 
* @Column(type="datetime") 
* @var string 
*/ 
private $lastupdate; 

/** 
* @Column(type="string", length=2) 
* @var string 
*/ 
private $countrycode; 

/** 
* @Column(type="string", length=20) 
* @var string 
*/ 
private $countrycurrency; 

/** 
* @Column(type="string", length=3) 
* @var string 
*/ 
private $currencycode; 


/** 
* @param \Doctrine\Common\Collections\Collection $property 
* @OneToMany(targetEntity="Region", mappedBy="country", cascade={"persist", "remove"}) 
*/ 
private $region; 


public function __get($property) { 
    return $this->property; 
} 

public function __set($property, $value) { 
    $this->property = $value; 
} 

} 

的application.ini摘錄

;; added for Doctrine2 Integration 
pluginPaths.Bisna_Application_Resource = "Bisna/Application/Resource" 

; ------------------------------------------------------------------------------ 
; Doctrine Cache Configuration 
; ------------------------------------------------------------------------------ 

; Points to default cache instance to be used. Optional is only one cache is defined 
resources.doctrine.cache.defaultCacheInstance = default 

; Cache Instance configuration for "default" cache 
resources.doctrine.cache.instances.default.adapterClass = "Doctrine\Common\Cache\ArrayCache" 
resources.doctrine.cache.instances.default.namespace = "Application_" 

; ------------------------------------------------------------------------------ 
; Doctrine DBAL Configuration 
; ------------------------------------------------------------------------------ 

; Points to default connection to be used. Optional if only one connection is defined 
resources.doctrine.dbal.defaultConnection = default 

; Database configuration 
;resources.doctrine.dbal.connections.default.parameters.wrapperClass = "" 
resources.doctrine.dbal.connections.default.parameters.driver = "pdo_mysql" 
resources.doctrine.dbal.connections.default.parameters.dbname = "zzzzz" 
resources.doctrine.dbal.connections.default.parameters.host = "localhost" 
resources.doctrine.dbal.connections.default.parameters.port = zzzz 
resources.doctrine.dbal.connections.default.parameters.user = "root" 
resources.doctrine.dbal.connections.default.parameters.password = "" 


; ------------------------------------------------------------------------------ 
; Doctrine ORM Configuration 
; ------------------------------------------------------------------------------ 

; Points to default EntityManager to be used. Optional if only one EntityManager is defined 
resources.doctrine.orm.defaultEntityManager = default 

; EntityManager configuration for "default" manager 
resources.doctrine.orm.entityManagers.default.connection  = default 
resources.doctrine.orm.entityManagers.default.proxy.autoGenerateClasses = true 
resources.doctrine.orm.entityManagers.default.proxy.namespace   = "Gesmoney\Entity\Proxy" 
resources.doctrine.orm.entityManagers.default.proxy.dir     = APPLICATION_PATH "/../library/Gesmoney/Entity/Proxy" 
resources.doctrine.orm.entityManagers.default.metadataDrivers.0.adapterClass   = "Doctrine\ORM\Mapping\Driver\AnnotationDriver" 
resources.doctrine.orm.entityManagers.default.metadataDrivers.0.mappingNamespace  = "Gesmoney\Entity" 
resources.doctrine.orm.entityManagers.default.metadataDrivers.0.mappingDirs[]   = APPLICATION_PATH "/../library/Gesmoney/Entity" 
resources.doctrine.orm.entityManagers.default.metadataDrivers.0.annotationReaderClass = "Doctrine\Common\Annotations\AnnotationReader" 
resources.doctrine.orm.entityManagers.default.metadataDrivers.0.annotationReaderCache = default 

回答

3

你忘了你的屬性$__get__set

public function __get($property) { 
    return $this->$property; 
} 

public function __set($property, $value) { 
    $this->$property = $value; 
} 
相關問題