Hey PHP guys... OOP question
I was wondering if you guys could explain something to me. I'm developing a new website based on CakePHP and am curious as whether it would be beneficial (faster and less code) to replace:
//Controller
$this->data['text_learn'] = $this->language->get('text_learn');
//Language
$_['text_learn'] = 'Learn About Our Website';
//View
<?php echo $text_learn; ?>
Simply with:
//View
<?php echo 'Learn About Our Website'; ?>
I'm trying hard to understand why it would be beneficial to have all that excess code when I could simply echo out the text; especially in cases where it is only used once.
13 comments
[ 3.1 ms ] story [ 35.1 ms ] threadThis is what I do with Kohana (a similar framework to cakePHP).
Umm if you have hard coded text (i.e. if that text never changes) why dont you just write it into the model? That seems perfectly fine (unless CakePHP does something screwy with views I dont know about :)) in MVC terms.
Try to think of instances where you might want to make a change that causes you to have to go and search through the code for a million different echoes spread all over the place. The 'extra code' is insurance against this eventuality.
If its a short little one shot deal, then don't sweat it.
With each one I had thought, "Oh it's just a little one shot deal." But after a few years, guess what you have thousands of?
Do it their way. Get used to it. It may take you a mere 2 seconds longer to type, but will save you minutes/hours/days later on.
It's really wonderful knowing that every single word that appears on your site is all coming from one source file. So if you do want to have it translated to Spanish or Chinese some day, you can just hand that file to a translator and voilá!
Not a flame, just a serious thought: from what I remember the RoR was worked on for a year or more - did it take longer than that to implement internationalization?
another common usage is to standardize error/success/etc messages. you always want one type of error to say the same thing, and a language file is a better place to put things than using a define.
having said that, its all about maximizing efficiency. if you don't think you'll actually save that much time in the future by putting things in the language file, maybe because you'll "never" internationalize, then its probably a process worth skipping for you. you can always just go back and make the changes later. it'll just be harder and take longer to do it later, as opposed to doing it now.
$this->children = array( 'common/search', 'account/login' );
The first one (common/search) loads fine but the second one doesn't. Am I doing this wrong? Thanks in advance!
It definitely would be faster to simply replace it with the 'echo' statement, but you need to decide if you might want to offer your website in different languages in the future. If internationalization is a possibility then you should keep it the way it is so that you can use different language files.
- Bryce
I tried Cake, Symphony, and Zend Framework - they are all quite strong but Cake and Symphony make you build your app 'their way', Zend Framework is looser than the others (more a collection of libraries) but is bloated, slow, and over-engineered.
My opinion is biased because I am a core developer.
Kohana's i18n system is pretty intuitive too. http://www.kohanaphp.com