During ThinkPHP development, a new libs folder is directly created under the Model folder because an external library is required to store the library file, then the files in require_once in the Model. However, namespace is used in the ThinkPHP framework Model, and this... during ThinkPHP development, a new libs folder is directly created under the Model folder because an external library is required to store the library file, then the files in require_once in the Model.
However, namespace is used in the ThinkPHP framework Model, and namespace is also used in this library. Now, the program seems to only search for the use in the namespace introduced by the Model, so the following error is reported:
Class 'falcon \ Model \ Thrift \ Transport \ TSocket 'not found error location FILE: D: \ wamp \ www \ Application \ Home \ Model \ HelloModel. class. php LINE: 165
Directory organization:
-Application-Home-Model-libs-here is the introduced library file-HelloModel. class. php
This is the HelloModel. class. php file.
I don't know how to solve this problem. Ask for help !!! Thank you !!!
Reply content:During ThinkPHP development, a new libs folder is directly created under the Model folder because an external library is required to store the library file, then the files in require_once in the Model.
However, namespace is used in the ThinkPHP framework Model, and namespace is also used in this library. Now, the program seems to only search for the use in the namespace introduced by the Model, so the following error is reported:
Class 'falcon \ Model \ Thrift \ Transport \ TSocket 'not found error location FILE: D: \ wamp \ www \ Application \ Home \ Model \ HelloModel. class. php LINE: 165
Directory organization:
-Application-Home-Model-libs-here is the introduced library file-HelloModel. class. php
This is the HelloModel. class. php file.
I don't know how to solve this problem. Ask for help !!! Thank you !!!
Since you use a single-entry framework, you cannot write require_once ('libs/thrift_require.php ') like this ');
1. You can try to change it to require_once ('./Application/Home/Model/libs/thrift_require.php ');
Require_once must be written as an absolute path.
2. the Directory of your libs file is wrong, because you have created it under the Model folder, which destroys the directory structure of the framework itself, thinkphp automatically imports the class in the model according to the namespace name. Incorrect modification: Create a libs folder in the model level directory, add your own namespace to each class file in the third-party library. custom classes cannot be automatically loaded without namespaces.
Do not create your own directory under the Framework directory, and do not break the directory structure of the Framework !!!
Ps: I often read your personal blog and find several excellent articles.
Fixed. You only need to modify the instantiation code:
$socket = new \Thrift\Transport\TSocket($host, $port);
If you add\
It will be searched from the root. If it is not added, it should be in the abovenamespace
.