search
Homephp教程php手册Thinkphp中import的几个用法详细介绍

下面附上import的几个用法介绍

1、用法一

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

2、用法二

import('Think.Test.Translate');
Think,表示系统根目录。既是:./ThinkPHP/
导入类库的路径是:./ThinkPHP/Lib/Test/Translate.class.php
结论:import('Think')是相对于系统目录的Lib目录而言

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、用法四

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

5、用法五

import还支持别名导入,使用别名导入,首先先定义别名文件,在项目配置目录下建立alias.php,定义项目中需要用到的类库别名。

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

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

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor