Internet Bandaid   [RSS Feed]

Archive for March 28th, 2014

Human readable text belong in database, views or language files – Best Practice

without comments

My response to a developer after I saw human readable text in model and controller files:
Your human readable error messages need to appear in the view file. Right now i see code like this in controller or model files:

$errMsg = “Birth date can’t be in the future”;
$view = load(‘template.php,’,$viewdata = array(‘error’=>$errMsg));

Human readable text should only be found in view files, language files and the database (database only if it’s user generated content).

Consider the following scenario:
We hired a journalist/writer to help us edit the text on our website. It only takes us maybe a few hours to teach the journalist how HTML works…it’s just open tag, text, then close tag. Now the journalist can go into the View folder, and start helping us fix spelling mistakes and everything.

If the journalist also had to go into Model or COntorller folder to modify text, they are going to be intimidated by “alien” language and risk breaking everything.

So try putting your error messages directly in the view and toggled on/off by if statements like

if($errorLog['weight']) echo ‘the error message’;

directly in the view file

Written by John Lai

March 28th, 2014 at 4:30 pm

Posted in Uncategorized