简体   繁体   English

CodeIgniter语言:最佳方法是什么?

[英]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.

相关问题 在Codeigniter中编写模型代码的最佳方法是什么 - What is the best way to write Model code in Codeigniter 在codeigniter中验证信用卡的最佳方法是什么? - What is the best way to validate a credit card in codeigniter 在 Codeigniter 中配置电子邮件的最佳方法是什么? - What is the best way to configure email in Codeigniter? 在codeigniter中在html上动态分配类的最佳方法是什么? - What is the best way to dynamically assign class on html in codeigniter? 使用Codeigniter在数据库中存储站点配置/选项的最佳方法是什么? - What is the best way to store site configuration/option in database using Codeigniter? 在 foreach 中处理 codeigniter php array_merge 的最佳方法是什么? - What the best way to deal with codeigniter php array_merge, in a foreach? 在此示例中,使jQuery / Ajax与CodeIgniter一起使用的最佳方法是什么? - What is the best way to get jQuery/Ajax to work with CodeIgniter in this example? 在Codeigniter中建立用户到用户消息传递功能的最佳方法是什么? - What's the best way to build a user to user messaging feature in codeigniter? 在codeigniter中获得具有相同电子邮件地址域的用户的最佳方法是什么? - What is the best way to get user with same email address domain in codeigniter? 如果我使用CodeIgniter,为数据库搜索清理$ _GET的最佳方法是什么? - What is the best way to sanitize $_GET for database search if I use CodeIgniter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM