A Zend-Framework project that uses Doctrine.
Data comes in form of objects. In my Zend View i access it like
$this->personData->getPersonAdress()->getPersonStreet();
Since its possible that a Person doesnt have an associated adress, we have to check if the personadress exists and if the personStreet is filled before echoing because otherwise an echoing NULL error may occur.
So we use some IFs with isset:
<? if($this->personData->getPersonaddress()) echo $this->personData->getPersonaddress()->getPersonstreet(); else echo "''"?>
Example (worst case):
<?
if(isset($this->address[0]) && is_object($this->address[0]))
{
$help2=$this->address[0]->getAddress();
if (isset($help2) && is_object($help2))
{
$help=$this->address[0]->getAddress()->getCountry();
if (isset($help) && is_object($help) && $help->getCountryId())
{
echo $this->address[0]->getAddress()->getCountry()->getCountryId();
}
}
}
?>
We need a solution or eventualla a Zend_view helper to simplify the procedure of echoing these values.
Any ideas would be highly appreciated..
I solved the issue myself by implementing a Zend View Helper that prints out every value ignoring errors that could occur by non-object properties or NULL associations.
This should be useful to everyone working with Zend Framework + Doctrine 2.
Usage
Instead of
Use (it delivers the value or default (0, third parameter) if not set)
Code following