Doctrine 2 Annotations and Zend Framework

I am working on a doctrine 2 sandbox (Beta3) and trying to apply the Zend Framework coding convention to place the main underscore for private class members. When I request an address while its private members are NOT underlined, I return the object as expected. When I add underscores, regenerate and refill db, and then run the same query, I get the following error messages:

PHP Note: Undefined index: id in ... Doctrine / ORM / Internal / Hydration / AbstractHydrator.php on line 184 PHP Fatal error: Failed to throw "Doctrine \ DBAL \ DBALException" with the message "Unknown column type". in ... Doctrine / DBAL / DBALException.php: 81

DQL query:

$q = $em->createQuery('select u from Entities\Address u where u.id = ?1'); $q->setParameter(1, '1'); $address = $q->getSingleResult(); 

ZFed Address Class:

 <?php namespace Entities; /** @Entity @Table(name="addresses") */ class Address { /** * @Id @Column(type="integer", length=11, name="id") * @GeneratedValue(strategy="AUTO") */ private $_id; /** @Column(type="string", length=255, name="street") */ private $_street; public function getId() { return $this->_id; } public function getStreet() { return $this->_street; } public function setStreet($street) { $this->_street = $street; } } 
+4
source share
1 answer

You will have to write _ before all your DQL queries.

Underscores before variables are a kind of Hungarian notation that we don't like the Doctrine team. Even the Zend Framework will reduce this style for the new code, as I understand it. Many other projects did the same, and PEAR2 even changed its standard in this regard.

+3
source

All Articles