Home  >  Article  >  php教程  >  ThinkPHP学习笔记多模板支持和多语言支持

ThinkPHP学习笔记多模板支持和多语言支持

WBOY
WBOYOriginal
2016-06-13 10:54:411133browse

首先是多模板支持:

 

需要在tpl上面新建red文件夹和对应的action的html模板

conf.php

//多模板支持

'TMPL_SWITCH_ON'=>true,

'TMPL_DETECT_THEME'=>true,

 

index.html

 

模板一

默认

 

 

多语言支持:

 

confg.php

 

[php]  

//多语言支持  

//是否开启多语言支持  

'LANG_SWITCH_ON'=>true,  

//安照Lang下的文件夹名称来写  

'DEFAULT_LANG'=>'zh-cn',  

//自动侦测语言  

'LANG_AUTO_DETECT'=>true,  

创建对应的文件夹语言包,所有action公共的命名为common.php,针对不同的action命名为不同的php文件;比如user.php

 

common代码:

 

[php]  

/** 

 * 针对全局的模块定义的中文文件 

 * 一:模板需要修改 

 * 二:配置文件需要修改 

 *  

 */  

return array(  

    'welcome'=>'welcome',  

    'lan'=>'english',  

    'usernamenull'=>'username is null',  

);  

?>  

 

设置语言方式一在common中设置

设计语言方式二:在Action中设置,使用L函数

 

[php]  

//快捷设置语言  

  L('demo','多语言测试');  

 

在页面引用并更换文字

[html]  www.2cto.com

欢迎:
 

语言:
 

demo:
 

简体中文
 

english
 

 

在Model中设置使用语言的方式:;需要加上前导符

如,在model中设置提示验证信息

 

[php]  

protected $_validate=array(  

        //在模型中添加国际化  

        array('username','require','',0,0,1),  

        array('username','checklen','用户名长度不合法',0,'callback',3),  

        array('password','require','用户名必填',0,0,1),  

        array('repassword','require','用户名必填',0,0,1),  

        array('password','repassword','密码不一致',0,'confirm',1),  

/           array('createip','email','邮箱格式不对',0,'regex',1),  

    );  

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn