I want to use a MVC-framework together with PHP to make a nice separation between code and presentation. I've currently started to look at CakePHP. It looks nice, but whats about all those magic strings?
Take a look at the code below (taken from the CakePHP cookbook):
class User extends AppModel {
var $name = 'User';
var $hasOne = 'Profile';
var $hasMany = array(
'Recipe' => array(
'className' => 'Recipe',
'conditions' => array('Recipe.approved' => '1'),
'order' => 'Recipe.created DESC'
)
);
}
It bothers me with those magic strings. Strings in code ought only to be text to be outputted!
One spelling mistake in 'Recipe.created DESC" and it won't work as expected. There's no intellisense/code completion to help here!
Also, what if I want to remane 'Recipe' to something else? I have to search manually through all the code and find out if it's regular text or one of the magic strings.
Are other PHP MVC-frameworks better? (read: less or no magic strings)
Any links on how to avoid magic strings (at least as much as possible)...?
What you are searching is the good ORM. Try using one of these:
More about ORM: http://en.wikipedia.org/wiki/Object-relational_mapping