[英]CodeIgniter Languages : What is the best way?
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 : 我最近开始使用CodeIgniter作为PHP MVC FrameWork,在CodeIgniter之前,我正在使用自己的MVC Pattern小型实现,因此,我使用的是基于常量的语言系统:
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";
等等,但是,当我开始使用CodeIgniter时,我看到它使用的是Language Class,因此,如果我们需要在视图中使用某种语言,则需要首先声明它,例如
$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 ? 然后将其传递给视图,第一种方法是,我们只需定义常量并加载文件,然后在视图中直接使用它……最佳方法是什么?
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.
因此,我建议您使用CodeIgniter方法。
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. 您还可以从CI可能添加的任何将来的语言功能中受益,并且可以扩展Language类以添加自己的功能。 For instance you could use this Multi-Language Library to load the language depending upon your URI.
例如,您可以使用此多语言库来加载语言,具体取决于您的URI。
Another MVC framework that isnt Codeigniter uses: 不是Codeigniter使用的另一个MVC框架:
$this->data['entry_rename'] = $this->language->get('entry_rename');
The way codeigniter does it seems very logical and a great way to do it. Codeigniter的执行方式似乎非常合乎逻辑,也是一种很好的方法。 The contants method doesnt appear to be a good way to do it.
竞争方法似乎不是一个很好的方法。
I agree with Chris. 我同意克里斯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.