Detailed introduction of several usages of import in Thinkphp

  • 2021-07-07 06:38:16
  • OfStack

The following is an introduction to several uses of import

1. Usage 1

import('@.Test.Translate');
@, representing the project root. Assume that the root directory is: App/
The path to import the class library is: App/Lib/Test/Translate. class. php
Conclusion: import ('@') is relative to the Lib directory of the project directory

2. Usage 2

import('Think.Test.Translate');
Think, representing the system root directory. Both:./ThinkPHP/
The path to import the class library is:./ThinkPHP/Lib/Test/Translate. class. php
Conclusion: import ('Think') is relative to the Lib directory of the system directory

3. Usage 3

import('ORG.Test.Translate');
Or
import('COM.Test.Translate');
ORG, Third Party Common Class Library Directory
COM, Enterprise Common Class Library Directory
Both are written in relation to./ThinkPHP/Extend/Library/.
The path to import the class library is:./ThinkPHP/Extend/Library/ORG/Test/Translate. class. php
Or
The path to import the class library is:./ThinkPHP/Extend/Library/COM/Test/Translate. class. php

Conclusion: import ('ORG') or import ('COM') is relative to the system extension class library directory (./ThinkPHP/Extend/Library/)

4. Usage 4

import('Blog.Test.Translate');
This writing is neither @, Think, nor ORG, COM, which will be treated as a grouped project directory.
The parsing result is: App/../Blog/Lib/Test/Translate. class. php
Conclusion: The fourth writing method is relative to the Lib catalogue of grouped project catalogue.

5. Usage 5

import also supports alias import, using alias import, first define alias file, establish alias. php in the project configuration directory, and define the class library alias needed in the project.


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

// You can use it like this 
import('page');


Related articles: