Thinkphp Learning Notes (13) multi-template support and multi-language support ____php

Source: Internet
Author: User

The first is multiple template support:

HTML template that needs to create a new red folder and corresponding action on the TPL

conf.php
Multi-Template Support
' Tmpl_switch_on ' =>true,
' Tmpl_detect_theme ' =>true,

Index.html

<a href= '? t=red ' > Template one </a><br>
<a href= '? t=default ' > Default </a><br>


Multi-language support:

confg.php

Multi-language support//
open MultiLanguage support
' lang_switch_on ' =>true,
///Follow LANG folder name to write
' Default_lang ' => ' ZH-CN ',
//Automatic Detection language
' Lang_auto_detect ' =>true,

Create the corresponding folder language pack, all action public named common.php, for different action named different PHP files; for example user.php

Common code:

<?php
/**
 * Chinese files for global modules
 * One: templates need to be modified
 * Two: config file needs to be modified
 */return
Array (
	' Welcome ' => ' welcome ',
	' LAN ' => ' 中文版 ', ' usernamenull ' => ' username '
	is null ',
);
? >

Set the language way one is set in the common

Design language Mode Two: Set in action, use L function

        Shortcut settings language
//        L (' demo ', ' Multi-language test ');

referencing and replacing text on a page

Welcome to:<!--{$Think .lang.welcome}--> <br>
language:<!--{$Think .lang.lan}--><br>
demo:<! --{$Think .lang.demo}--><br>
<a href= '? L=ZH-CN ' > Simplified Chinese </a><br>
<a href= '? l= En-US ' >english</a><br>

Set the way to use languages in model:<!--{%welcom}-->; needs to be preceded by a leader

For example, set prompt validation information in model

	Protected $_validate=array (
			///Add internationalized array to the Model
			(' username ', ' require ', ' <!--{%welcom}--> ', 0,0,1),
			Array (' username ', ' checklen ', ' username length not valid ', 0, ' callback ', 3),
			Array (' Password ', ' require ', ' username required ', 0,0,1),
			Array (' Repassword ', ' require ', ' username required ', 0,0,1),
			Array (' Password ', ' Repassword ', ' inconsistent password ', 0, ' confirm ', 1),
//			Array (' Createip ', ' email ', ' wrong mailbox format ', 0, ' regex ', 1)
		;


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.