Perfect solution to the namespace problem in the ThinkPHP controller, thinkphp namespace
In TP a few days ago, I used PHP to bring my own class, because of the namespace, I encountered a small problem. Because the namespace is used in ThinkPHP, if it is in the Home namespace, directly execute the following code
<Pre name = "code" class = "php"> $ datetime = new DateTime ($ basedate, new DateTimeZone ($ timezone ));
Then it is equivalent
$ Datetime = new \ Home \ DateTime ($ basedate, new <span style = "font-family: Arial, Helvetica, sans-serif; ">\home \ </span> <span style =" font-family: Arial, Helvetica, sans-serif; "> DateTimeZone ($ timezone); </span>
It is displayed that this is incorrect DateTime and DateTimeZone are built-in class files in PHP and should be in the Root Space. The correct execution method is as follows:
$ Datetime = new \ DateTime ($ basedate, new \ DateTimeZone ($ timezone ));
Note:If you do not specify a namespace when instantiating a class, PHP uses the current namespace. If the current namespace is not specified, the current namespace is the root space, that is '\
The above is a perfect solution to the namespace problem in the ThinkPHP controller. It is all the content shared by the editor. I hope to give you a reference and support for the help house.