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->data['text_learn'] = $this->language->get('text_learn');<p>//Language<p>$_['text_learn'] = 'Learn About Our Website';<p>//View<p><?php echo $text_learn; ?><p>Simply with:<p>//View<p><?php echo 'Learn About Our Website'; ?><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.
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?<p>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.<p>If its a short little one shot deal, then don't sweat it.
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
Dude, before you get too deep - use Kohana; it doesn't shackle you and it is quite powerful.<p>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.<p>My opinion is biased because I am a core developer.<p>Kohana's i18n system is pretty intuitive too.
<a href="http://www.kohanaphp.com" rel="nofollow">http://www.kohanaphp.com</a>
Well I would just pass the language model into the view - it seems the better method (and still in keeping with MVC methodology).<p>This is what I do with Kohana (a similar framework to cakePHP).<p>Umm if you have hard coded text (i.e. if that text <i>never</i> changes) why <i>dont</i> 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.
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:<p>$this->children = array(
'common/search',
'account/login'
);<p>The first one (common/search) loads fine but the second one doesn't. Am I doing this wrong? Thanks in advance!
Hi Eintnohick,<p>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.<p>- Bryce