Last night, I had a problem with my father-in-the-middle problem. First of all, let me talk about my code. I set up an index controller and then there is an index method in the controller. All page templates are available.
if ( ! defined(‘BASEPATH‘)) exit(‘No direct script access allowed‘);
class Index extends CI_Controller{ public function index(){ $this->load->view(‘index.html‘); }}
Then you can run it in the browser. The error page is as follows.
I thought it was a control error when I saw this error message, but I checked it carefully and found that there was no error. Then I began to wonder if it was a problem with permissions on win7. However, I add the admin permission to the folder. I found this problem ~!~
I thought it was a framework package because I accidentally deleted something. Then I downloaded the new framework from the CI official website and set up a new project framework. I found this error. [Note: My heart broke, and I hit the mouse a few times. The poor mouse should be my venting product! ~]. In this way, I had to go over for a few hours. I had to look at the time on my cell phone. I am still thinking about this problem in bed. I have used the CI framework for several projects. Why is there no such problem ....... then I thought about the solution and fell asleep .........
The next day, I quickly came to the company to build a new framework with the same errors last night, and then compared it with the previous project using the CI framework. Ke, I really found out the reason. It turns out that my controller name and method name are different. Then I changed the error reporting framework and changed the method name. I checked it.
Then I began to think about why an error would be reported if the class name is the same as the method name.
........................
Think about it. It turns out that each class has an implicit constructor with the same name. If you write a method name that is the same as the class name, it will conflict with the constructor.
In fact, there is another way to solve this problem, that is, to inherit the constructor of the parent class in the constructor, because the subclass can write the parent class method so that no error will be reported.
<?php if ( ! defined(‘BASEPATH‘)) exit(‘No direct script access allowed‘);class Index extends CI_Controller { public function __construct(){ parent::__construct(); } public function index() { $this->load->view(‘show.html‘); } }