php codeigniter 语言,php – codeigniter模板引擎,包括语言解析器
不幸的是,CI內(nèi)置的模板解析器類(lèi)沒(méi)有此功能.你可以在
sparks directory中環(huán)顧四周,有多個(gè)火花集成了許多模板引擎,如smarty或twig,可以通過(guò)調(diào)整來(lái)創(chuàng)建這樣的東西.
此外,您可以嘗試擴(kuò)展CI_Parser類(lèi)來(lái)為您執(zhí)行此操作,如下所示:
class MY_Parser extends CI_Parser {
const LANG_REPLACE_REGEXP = '!\{_\s*(?[^\}]+)\}!';
public $CI = null;
public function parse($template, $data, $return = FALSE) {
$this->CI = get_instance();
$template = $this->CI->load->view($template, $data, TRUE);
$template = $this->replace_lang_keys($template);
return $this->_parse($template, $data, $return);
}
protected function replace_lang_keys($template) {
return preg_replace_callback(self::LANG_REPLACE_REGEXP, array($this, 'replace_lang_key'), $template);
}
protected function replace_lang_key($key) {
return $this->CI->lang->line($key[1]);
}
}
這將使用$this-> lang-> line(‘password’)替換{_ password}之類(lèi)的部分.可以針對(duì)您喜歡的版本調(diào)整模式.
將其置于application / libraries / MY_Parser.php和CI之下應(yīng)該選擇它,不需要更改控制器代碼,如Extending Native Libraries部分所述.
總結(jié)
以上是生活随笔為你收集整理的php codeigniter 语言,php – codeigniter模板引擎,包括语言解析器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php smarty关闭缓存,php+S
- 下一篇: 平民合金怎么打,我用仨只冰雹都打不过