search
Homephp教程php手册ThinkPHP学习笔记多模板支持和多语言支持

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

Jun 13, 2016 am 10:54 AM
redthinkphpandstudysupportNewtemplatenoteslanguage

首先是多模板支持:

 

需要在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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)