: This article mainly introduces Thinkphp313 using namespace. if you are interested in the PHP Tutorial, refer to it. After using JAVA for many years, our company now uses thinkphp. if namespace is not introduced, it is very uncomfortable. when there are many classes, it is easy to define duplicate names.
So start using namespace. some notes.
When using namespace:
1. call class: Call the namespace class. after import () is used, the full path of namespace must be used during instantiation. For example:
Import ('@. UNI. vendor. disngding. dingservice'); class DingAction extends Action {$ dtSvr = new \ vendor \ disngding \ DingService (); $ rsc}
2. the class defined by namespace. the class without namespace is called.
All the classes from import will be under the \ root directory. Therefore, add \
Namespace vendor \ dingding; import ('@. UAI. dal. DSysUser'); class corpUserService {public static function getUserCorpIdAndAgentIdByUsername ($ username) {$ userSvr = new \ DSysUser ();}
3. classes not introduced. in the classes defined by namespace, all classes must be rooted. for example, Model () must be written as \ Model ();
The preceding section describes Thinkphp313's usage of namespace, including the Thinkphp313 notes. if you are interested in the PHP Tutorial.