Null operation: An object (Controller) Call method that does not exist by itself
NULL controller: The specified class was not found when instantiating the Controller object
First, create a new Ceshi module under the application file and follow the home module under the Ceshi module to create the same folder, such as:
1) Create a new login controller under the Controller folder:
<?phpnamespace ceshi\controller;use think\controller;class Logincontroller extends controller{ public function login () { echo] Welcome to login! "; }}
2) Address bar input access address: Http://localhost/wamp/thinkphp/index.php/Ceshi/Login/login
First, the address bar to access the non-existent method, what happens?
Http://localhost/wamp/thinkphp/index.php/Ceshi/Login/loginSSS
From this page, we can know:
(1) This interface exposes the code we use to write the tool and exposes the thinkphp version number, which can be exploited if the hacker finds a bug in the version number.
(2) Second, this interface is very unfriendly, for users, they do not understand and do not know what is wrong.
How to give a more secure, more friendly hint?
There is a method in the parent class that we can do with this:
The first method: Make an empty template
1) Create a Ceshi folder under the View folder with the following path:
Loginsss.html
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
2) Visit Http://localhost/wamp/thinkphp/index.php/Ceshi/Login/loginsss again
This is much more friendly than just the code, but it is not possible to make a template every time we enter a non-existent method, which is impractical, and we don't know what the user will be typing next, so this method is not feasible.
The second method: Do an empty method: _empty () method
<?phpnamespace ceshi\controller;use think\controller;class Logincontroller extends controller{ public function login () { echo] Welcome to login! "; } Public Function _empty () { echo] The action method you accessed does not exist! "; }}
This way, no matter what kind of empty method you access, you will see "The action method you accessed does not exist!" ”
http://localhost/wamp/thinkphp/index.php/Ceshi/Login/Logins
Http://localhost/wamp/thinkphp/index.php/Ceshi/Login/aaa
Second, in the address bar to access the non-existent controller, what happens? The same error occurred
Workaround:
Create a new empty controller:
EmptyController.class.php
<?phpnamespace ceshi\controller;use think\controller;class Emptycontroller extends controller{public function _empty () { echo "the controller you have accessed is wrong"; }}
Re-visit http://localhost/wamp/thinkphp/index.php/Ceshi/Main/login
Change a http://localhost/wamp/thinkphp/index.php/Ceshi/mmmn/login
This will solve the problem of NULL controller and empty operation ~.~.~
thinkphp NULL controller and NULL operation and corresponding solution