As I suggested, why just not create a methot $content->getCategoryName()
and put all the logic there? I guess a matter of preference but
following this approach, you will be free from problems as the original
and you will not need a get* and has* method for each function you want
to have.
Kupo
Nicolas Perriault wrote:
> 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; ?>
>
> ++
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---