Home >PHP Framework >ThinkPHP >Five ways to use import in Thinkphp (with code examples)

Five ways to use import in Thinkphp (with code examples)

藏色散人
藏色散人forward
2021-12-20 11:59:332339browse

The following thinkphp framework tutorial column will introduce you to the five usage methods of import in thinkphp. I hope it will be helpful to friends in need!

Attached below are several introductions to how to use import

1. Usage method one

	import('@.Test.Translate');
	@,表示项目根文件夹。假定根文件夹是:App/
	导入类库的路径是:App/Lib/Test/Translate.class.php
	结论:import('@')是相对于项目文件夹的Lib文件夹而言

2. Method 2

	import('Think.Test.Translate');
	Think,表示系统根文件夹。

3. Method 3

	import('ORG.Test.Translate'); 
	或
	import('COM.Test.Translate'); 
	ORG, 第三方公共类库文件夹
	COM, 企业公共类库文件夹
	两种写法都是相对于./ThinkPHP/Extend/Library/ 而言。
	导入类库的路径是:./ThinkPHP/Extend/Library/ORG/Test/Translate.class.php
	或
	导入类库的路径是:./ThinkPHP/Extend/Library/COM/Test/Translate.class.php

	结论:import('ORG')或import('COM')是相对于系统扩展类库文件夹而言(./ThinkPHP/Extend/Library/)

4. Method 4

	import('Blog.Test.Translate'); 
	这样的写法既不是@。Think的写法,有不是ORG。COM的写法。会被当作分组的项目文件夹来处理。
	解析结果是:App/../Blog/Lib/Test/Translate.class.php
	结论:第四种写法,是相对于分组项目文件夹的Lib文件夹而言的写法。

5. Method 5

import also supports alias import. To use alias import, first define the alias file. Create alias.php in the project configuration folder to define the class library aliases that need to be used in the project.

         return array(
              'page' =>  LIB_PATH.'Common/page.class.php',
         );

         //这样使用就可以
         import('page');

Recommended: "The latest 10 thinkphp video tutorials"

The above is the detailed content of Five ways to use import in Thinkphp (with code examples). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete