

Hey PHP guys... OOP question - eintnohick

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:<p>//Controller<p>$this-&#62;data['text_learn'] = $this-&#62;language-&#62;get('text_learn');<p>//Language<p>$_['text_learn']   = 'Learn About Our Website';<p>//View<p>&#60;?php echo $text_learn; ?&#62;<p>Simply with:<p>//View<p>&#60;?php echo 'Learn About Our Website'; ?&#62;<p>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.
======
noonespecial
Its about maintainability. Is "learn about our website" the only thing you
ever want to echo? Will it always be only in english? Might you want to echo
it other places, or use it in different circumstances?

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.

~~~
sivers
Yes yes yes! I can't emphasize this enough. My _biggest regret_ in 10 years of
building cdbaby.com was that when I wanted to make it multi-lingual, 7 years
into it, I was screwed! All of the language was spread around so many little
print/echo statements in 10,000 different places.

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á!

~~~
walesmd
I imagined your biggest regret would be wasting all of that time trying to
force the site to work on RoR and then finally relenting and switching back to
PHP.

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?

------
edb
You should use the latter but pass it through the __() function. Read the docs
on I internationalisation. There is a pretty standard way of translating text
in cake

~~~
eplawless
edb has it. [http://book.cakephp.org/view/162/Internationalizing-Your-
App...](http://book.cakephp.org/view/162/Internationalizing-Your-Application)

------
Ixiaus
Dude, before you get too deep - use Kohana; it doesn't shackle you and it is
quite powerful.

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>

------
ErrantX
Well I would just pass the language model into the view - it seems the better
method (and still in keeping with MVC methodology).

This 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.

------
eintnohick
Hey guys, thanks a bunch for the help. It makes better sense now. Thinking
about what yall said, how do can you load a controller from a controller. I
tried:

$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!

------
bmickler
Hi Eintnohick,

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

------
eintnohick
Man you guys are awesome!! Thanks a bunch. I figured out my controller prob so
yall don't need to worry about that.

------
Zarathu
Eek, that sounds way complicated. Glad we don't have to deal with that in RoR.

