I currently have a writers MVC that is working. I have a firstname and lastname property. On the index I want to display the full name. I understand that this can be done several ways.
I can write the logic in the view
echo $writer['Writer']['firstname'] . " " . $writer['Writer']['lastname'];
I can write a helper function to do this and keep my view clean. This is how I currently do it.
echo fullName($writer['Writer']['firstname'], $writer['Writer']['lastname']);
I was wondering however if it would be a better to create a writer class that has a fullname method. Then I could simplify my view a bit more.
echo $writer->fullname
So, I know how to write helpers and this works, assuming that building a class is the way to go, when is the right time, after a query to instantiate each object? I assume in the controller. Further, where would my class reside?
create a helper CustomHelper (anything you like) in your
View/Helper/.Then a method fullName:
You can also make a behavior to format in on find() already.
It depends where you are going to use it. If it is only view related, helpers would suffice. If you need it at controller/model level you might want to use the model layer to concatenate.