0

Hi I'm trying to get cake to show full names in archival standards. I need the names to be shown in the format of "LASTNAME Firstname", with lastname being all caps and the first letter of first name in caps. I have in my model first_name and last_name and have managed to combine them via virtual field, but am having problems with the two different caps mods.

Please and thank you.

1
  • Why not just formatting on output? (echo)
    – mark
    Oct 18, 2013 at 16:41

3 Answers 3

0

in your afterfind callback: strtoupper(lastname) and ucfirst(strtolower($firstname)) or you could do this in your beforesave and save the fields like this in your database.

or as suggested by mark: why not just do this in your views?

0
public $virtualFields = array(
   'vf_full_name' => 'CONCAT(UPPER(`last_name`), " ", UPPER(SUBSTRING(`first_name`, 1, 1)), LOWER(SUBSTRING(`first_name`, 2)))',
);
0

Do this in your view. Saving your data in the database in this format will just lead to headaches in the future. For example, if you save the surname “DiMaggio” in the all-uppercase format (“DIMAGGIO”) you can’t then just convert it to all-lowercase and capitalize the first letter; that gives you “Dimaggio” which is wrong.

As I say, just do it in your view. First name and last name are separate, which is great.

<p class="name">
  <span class="last-name"><?php echo h($user['User']['last_name']); ?></span>,
  <span class="first-name"><?php echo h($user['User']['first_name']); ?></span>
</p>

I’d also convert the last name to uppercase which CSS rather than HTML, which is more semantic.

.last-name {
    text-transform: uppercase;
}

It’s easier to change a CSS rule than to go through view files and remove strings wrapped in strtoupper() function calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.