Namespaces-questions about using namespace in ThinkPHP

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.