Home >Backend Development >PHP Tutorial >Problems and solutions for ThinkPHP using public language packages_PHP tutorial

Problems and solutions for ThinkPHP using public language packages_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:11:511150browse

Problems and solutions for using public language packages in ThinkPHP
I am using ThinkPHP3.1.3. Screenshot of my project


Note: Because my projects are grouped, I will now use the Admin group to create a language pack as an example.

First, create a zh-cn folder in Lang under the app in the root directory of the project, then create an Admin group under the zh-cn folder, and create user.php in Admin. For language pack definition, please refer to the following


Write the language information in user.php as follows

return array(

'SITE_TITLE' => '24 Youth',

'SITE_URL' => 'http://jahan.sinaapp.com/',

'SITE_KEYWORDS' => 'php thinkphp',

.............

);

Next, configure it in config.php (which is the configuration information file of your own project)

return array(

'LANG_AUTO_DETECT' => FALSE, //Turn off the automatic detection of languages. If you have multiple languages, you can turn it on

'LANG_SWITCH_ON' => TRUE, //Enable the language pack function, this must be enabled

'DEFAULT_LANG' => 'zh-cn', //zh-cn folder name /lang/zh-cn/common.php

);

You also need to add code to tags.php in the project (usually located in the Conf directory, if not, you can create it yourself), as follows

return array(

'app_begin' => array(

'CheckLang',

),

);

Before the app runs, this configuration file will be loaded to call the CheckLang method. I ran the project and found that an error occurred. The error message was "Class 'CheckLangBehavior' not found".

Because the 'CheckLangBehavior' class is not found, we can download a full version of TP and find CheckLangBehavior.class.php. The screenshot is as follows


Put this class in the Extend directory of the project, or in the Lib directory. This allows you to use custom language packs.

Language pack call:

If called in Action, the format is L('site_name')

If called in a template file, the format is {:L('site_name')}


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477291.htmlTechArticle Problems and solutions for ThinkPHP using public language packages. I am using ThinkPHP3.1.3. Screenshot of my project Note: Because my projects are grouped, now create a new language pack in the Admin group...
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