开发者

CodeIgniter Languages : What is the best way?

开发者 https://www.devze.com 2023-01-13 02:10 出处:网络
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 :

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"; , whe开发者_开发百科n 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 ?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消