命名空间 是一个虚拟的目录
TP框架的初始命名空间是:ThinkPHPLibrary 相当于一个根
在TP框架下命名空间里面使用(反斜杠)
代表初始命名空间
根命名空间不代表初始命名空间
根命名空间是基于初始命名空间的
根命名空间在TP框架下有两块
1.Library文件夹下所有的文件夹都是根命名空间
2.在程序文件夹内 以模块名命名的
每个类都有命名空间
命名空间 从根开始写
示例:
namespace HomeController; 定义命名空间
use ThinkController; 使用命名空间 从根开始写 最后面跟类名
引入一个类,必须有一个命名空间
1.可以放在Library文件夹下 新建一个文件夹 如 FenYe namespace FenYe;
用的时候 FenYePage(10,5);
2.可以放在Home文件夹下 新建一个文件件 如FenYe namespace HomeFenYe;
用的时候 HomeFenYePage(10,5);
在TP框架下命名空间里面使用代表的是初始命名空间(ThinkPHPLibrary)
1.系统目录下根命名空间是ThinkPHPLibrary下面的文件夹名称命名的
2.模块的根命名空间是以模块名命名的
在定义命名空间的时候需要从根写起例如:HomeController 例如:ThinkModel
如果要使用某个类文件,引入该类命名空间的时候:
使用use关键字,后面写该类的命名空间 后面加上 "文件名"
如果不想引入命名空间:在造类的对象的时候可以使用(初始命名空间)来找到对应的类
例如:new ThinkPage(30);