Greg Freeman a écrit :
> <?php echo $content->getcategory()->getName() ?>
>
> And the content does not have a category (i.e category_id in the
> content table is null) it causes an error. Now of course you could use
> php like isset etc but wouldn't that be breaking separation of logic
> etc.
If your content can have no associated category, then you shouldn't call
the category from it ;)
But you can provide a hasCategory method to test its presence :
public function hasCategory()
{
return (!is_null($this->getCategoryId()));
}
And in your template :
<?php if($content->hasCategory()): ?>
<?php echo $content->getCategory()->getName() ?>
<?php endif; ?>
++
--
Nicolas Perriault http://www.clever-age.com
Clever Age - conseil en architecture technique
GSM: +33 6 60 92 08 67 Tél: +33 1 53 34 66 10
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---