Home Backend Development PHP Tutorial ThinkPHP多语言支持与多模板支持概述_PHP

ThinkPHP多语言支持与多模板支持概述_PHP

May 31, 2016 pm 07:30 PM
thinkphp multi-language support

ThinkPHP

本文以实例形式简述了ThinkPHP的多语言支持与多模板支持。是ThinkPHP中非常重要的技巧,分享给大家供大家参考。具体如下:

一、ThinkPHP多语言支持:

config.php配置文件中添加:

//多语言支持设置
'LANG_SWITCH_ON'=>true,
'DEFAULT_LANG'=>'zh-cn',
'LANG_AUTO_DETECT'=>true,
'LANG_LIST'=>'en-us,zh-cn,zh-tw',

Copy after login

Home/Lang/文件夹下建立三个文件夹,分别为zh-cn ,en-us ,zh-tw 分别代表简体中文,英文,繁体中文

文件夹下可以建立与模板对应的文件,或者公用文件common.php

zh-cn/common.php页面如下:

<&#63;php
return array(
 'welcome'=>'你好',
 'lan'=>'简体中文', 
);
&#63;>

Copy after login

en-us/common.php页面如下:

<&#63;php
return array(
 'welcome'=>'how are you fine&#63;',
 'lan'=>'english', 
);
&#63;>

Copy after login

zh-tw/common.php页面如下:

<&#63;php
return array(
 'welcome'=>'你好',
 'lan'=>'簡體中文', 
);
&#63;>
Copy after login

模板index.php代码如下:

欢迎:{$Think.lang.welcome} 语言:{$Think.lang.lan}
<a href="&#63;l=zh-cn" rel="external nofollow" >简体中文</a>
<a href="&#63;l=en-us" rel="external nofollow" >english</a>
<a href="&#63;l=zh-tw" rel="external nofollow" >繁體中文</a>

Copy after login

或者在Action的方法里直接定义:L('demo','测试');这样,在模板里就可以直接应用了:{$Think.lang.demo}
对于在模型中,比如有:array('uname','require','用户名必填');可以这么用:array('uname','require','%name');

二、ThinkPHP多模板支持:

config.php配置文件中添加:

//多模板支持
 'TMPL_SWITCH_ON'=>true,
 'TMPL_DETECT_THEME'=>true,

Copy after login

/Home/Tpl/下建立其它皮肤文件夹,比如文件夹red,其中的文件与default文件中的一样。

在模板文件中添加:

<a href="&#63;t=red" rel="external nofollow" >红</a>
<a href="&#63;t=default" rel="external nofollow" >默认</a>
Copy after login

相信本文所述实例对大家ThinkPHP学习和开发有所帮助。

Statement of this Website
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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to fix Windows Hello unsupported camera issue How to fix Windows Hello unsupported camera issue Jan 05, 2024 pm 05:38 PM

When using Windows Shello, a supported camera cannot be found. The common reasons are that the camera used does not support face recognition and the camera driver is not installed correctly. So let's take a look at how to set it up. Windowshello cannot find a supported camera tutorial: Reason 1: The camera driver is not installed correctly 1. Generally speaking, the Win10 system can automatically install drivers for most cameras, as follows, there will be a notification after plugging in the camera; 2. At this time, we open the device Check the manager to see if the camera driver is installed. If not, you need to do it manually. WIN+X, then select Device Manager; 3. In the Device Manager window, expand the camera option, and the camera driver model will be displayed.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Pros and Cons Analysis: A closer look at the pros and cons of open source software Pros and Cons Analysis: A closer look at the pros and cons of open source software Feb 23, 2024 pm 11:00 PM

Pros and cons of open source software: Understanding the pros and cons of open source projects requires specific code examples In today’s digital age, open source software is getting more and more attention and respect. As a software development model based on the spirit of cooperation and sharing, open source software is widely used in different fields. However, despite the many advantages of open source software, there are also some challenges and limitations. This article will delve into the pros and cons of open source software and demonstrate the pros and cons of open source projects through specific code examples. 1. Advantages of open source software 1.1 Openness and transparency Open source software

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

Does PyCharm Community Edition support enough plugins? Does PyCharm Community Edition support enough plugins? Feb 20, 2024 pm 04:42 PM

Does PyCharm Community Edition support enough plugins? Need specific code examples As the Python language becomes more and more widely used in the field of software development, PyCharm, as a professional Python integrated development environment (IDE), is favored by developers. PyCharm is divided into two versions: professional version and community version. The community version is provided for free, but its plug-in support is limited compared to the professional version. So the question is, does PyCharm Community Edition support enough plug-ins? This article will use specific code examples to

ASUS TUF Z790 Plus is compatible with ASUS MCP79 memory frequency ASUS TUF Z790 Plus is compatible with ASUS MCP79 memory frequency Jan 03, 2024 pm 04:18 PM

ASUS tufz790plus supports memory frequency. ASUS TUFZ790-PLUS motherboard is a high-performance motherboard that supports dual-channel DDR4 memory and supports up to 64GB of memory. Its memory frequency is very powerful, up to 4800MHz. Specific supported memory frequencies include 2133MHz, 2400MHz, 2666MHz, 2800MHz, 3000MHz, 3200MHz, 3600MHz, 3733MHz, 3866MHz, 4000MHz, 4133MHz, 4266MHz, 4400MHz, 4533MHz, 4600MHz, 4733MHz and 4800MHz. Whether it is daily use or high performance needs

See all articles