CodeIgniter reusable message library

时间秒杀一切 提交于 2019-12-22 01:06:50

问题


I'm using Message library (http://codeigniter.com/wiki/Message/) to display error messages on my site. This is the code that I'm using to display a message:

$this->message->set('error',$this->config->item('error.login'));

Right now I'm storing common messages in my config file (config/config.php) instead of writing the message every time. Is there a better way to do it? The config file is getting very long.

What I'm looking for is a better way to store re-usable text strings.


回答1:


CodeIgniter's language class is what you're looking for: CI Language Class

$this->message->set('error',$this->lang->line('error.login'));



回答2:


A config file is more or less how you'd want to do it. It is simple, clear and light. But just because you are keeping it in a config file, that does not mean you need to keep it in config.php. The Config class allows you to have multiple config files, so have a special one for messages. Heck, you could even have several special ones for languages, and leave the one you are looking for in the config.php file!

 $this->config->load( $this->config->get( "language_file_name" ) );


来源:https://stackoverflow.com/questions/7120746/codeigniter-reusable-message-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!