ThinkPHP learning notes multi-template support and multi-language support _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.