php codeigniter 语言,php – codeigniter模板引擎,包括语言解析器
不幸的是,CI內置的模板解析器類沒有此功能.你可以在
sparks directory中環顧四周,有多個火花集成了許多模板引擎,如smarty或twig,可以通過調整來創建這樣的東西.
此外,您可以嘗試擴展CI_Parser類來為您執行此操作,如下所示:
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}之類的部分.可以針對您喜歡的版本調整模式.
將其置于application / libraries / MY_Parser.php和CI之下應該選擇它,不需要更改控制器代碼,如Extending Native Libraries部分所述.
總結
以上是生活随笔為你收集整理的php codeigniter 语言,php – codeigniter模板引擎,包括语言解析器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php smarty关闭缓存,php+S
- 下一篇: 平民合金怎么打,我用仨只冰雹都打不过