Doctrine 2 query returned object has no property or methods
I am using Doctrine 2 and Zend Framework 1.11. I have set up my Doctrine intergration and it seams to be working in that, I able to get and instance on an Entity Manager to work with. However, I am baffled by the behaviour of the following line in the controller class:
$transfercurrency = $this->entityManager->getRepository('Gesmoney\Entity\Country')->findBy(array('countrycode' => $transfercountry));
When I do a var_dump($transfercurrency), I get an object with a whole bunch of properties, infact, it doesn't look right to me. I tried to post it on pastie but it will not let me because its more than 100kb. I therefore just pasted about a quarter of it enter link description here. Also using Netbeans there seem to be no properties or methods for the returned object he开发者_运维技巧nce when I invoke code complete I get nothing. When I do var_dump($transfercurrency[0]->id), I get the following error;
Notice: Undefined property: Gesmoney\Entity\Country::$property in /shared/www/dev.gesmoneylatest.com/library/Gesmoney/Entity/Country.php on line 55 NULL
Its quite a long post but I hope someone has the answer to my problem. Thanks.
Controller class
<?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);
}
}
Entity
<?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 excerpt
;; 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
You forgot the $
on your properties for __get
and __set
public function __get($property) {
return $this->$property;
}
public function __set($property, $value) {
$this->$property = $value;
}
精彩评论