views:

61

answers:

2

i recently start using CodeIgniter as PHP MVC FrameWork , before CodeIgniter, i was using my own small implementation of MVC Pattern , So , i was using language system build on constants like :

define( CONTACT_US , ' Contact Us ' ); and so ... , but when i start using CodeIgniter , i see it use Language Class , so if we need to use a language in a view we need first to declare it like $lang['mainpage_contact'] = "Contact Us"; , when we need to pass it to view ,

$this->lang->load('mainpage' ); 
$date['contact'] = $this->lang->line('mainpage_contact');

and then pass it to view , in the first way , we can just define the constant and load the file , then use it directly in the view ... what is the best way ?

+2  A: 

It's always best to stick to the method your chosen framework uses. Then if you need help, or another programmer has to work on it, there's no confusion. So I'd recommend going with the CodeIgniter way.

You also get the benefit of any future language features CI may add, and you can extend the Language class to add your own functionality. For instance you could use this Multi-Language Library to load the language depending upon your URI.

Chris Gaunt
logically , true , but in practice the current way take more time , what is the advantage of using it other than it is framework standard ?
shox
Using the framework's standard way of doing things will in the end save you massive amounts of time. When it comes to translations the way CI does it enables others to easily create language files that can be used in your application without any core modifications.
Yorick Peterse
A: 

Another MVC framework that isnt Codeigniter uses:

$this->data['entry_rename'] = $this->language->get('entry_rename');

The way codeigniter does it seems very logical and a great way to do it. The contants method doesnt appear to be a good way to do it.

I agree with Chris.

Kieran Andrews