ThinkPHP learning notes multi-template and multi-language support. First, multi-template support: Solution a is first supported by multiple templates:
You need to create a red folder and an html template for the corresponding action on the tpl.
Conf. php
// Supports multiple templates
'Tmpl _ SWITCH_ON '=> true,
'Tmpl _ DETECT_THEME '=> true,
Index.html
Template 1
Default
Multi-language support:
Confg. php
[Php]
// Multi-language support
// Whether to enable multi-language support
'Lang _ SWITCH_ON '=> true,
// Write according to the folder name under Lang
'Default _ lang' => 'zh-cn ',
// Automatic language detection
'Lang _ AUTO_DETECT '=> true,
Create a corresponding folder language pack. all actions are named common. php in the public and different php files are named for different actions. for example, user. php
Common Code:
[Php]
/**
* Chinese files defined for global modules
* 1. the template needs to be modified.
* 2: the configuration file needs to be modified.
*
*/
Return array (
'Welcome '=> 'Welcome ',
'LAN '=> 'English ',
'Usernamenable' => 'username is Null ',
);
?>
Set Language 1 in common
Design language Method 2: Set in Action and use the L function
[Php]
// Shortcut language
L ('demo', 'multilingual test ');
Reference and replace text on the page
[Html] www.2cto.com
Welcome:
Language:
Demo:
Simplified Chinese
English
Set the language used in the Model: ; A leading character must be added.
For example, set the prompt verification information in the model.
[Php]
Protected $ _ validate = array (
// Add internationalization to the model
Array ('username', 'require ',' ', 0, 0, 1 ),
Array ('username', 'checklen', 'invalid username length ', 0, 'callback', 3 ),
Array ('password', 'require ', 'username mandatory', 1 ),
Array ('repassword', 'require ', 'username mandatory', 1 ),
Array ('password', 'repassword', 'inconsistent password', 0, 'Confirm', 1 ),
/Array ('createip', 'Email ', 'wrong email format', 0, 'regex', 1 ),
);
Pipeline needs to create a red folder on tpl and the corresponding action html template conf. php // multiple templates support TMPL_SWITCH_ON = true, TMPL_DETECT_THEME = true, index.html...