ThinkPHP's suffix Operation Method Configuration strikes

Source: Internet
Author: User
I added a method list {code ...} OK, an error is reported, and then the suffix {code...} is configured ...} add the suffix {code...} to the system Keyword Method ...} OK. I will open the browser again and you will think about what will happen. Maybe it will continue to report the error of illegal index operation, but there is actually no error...

I added a method list.


  ";} Public function index () {// index () method public // echo'
Hello Think php'; // $ config = C (''); // read all configuration items // dump ($ config); // dump () is the ThinkPHP function used to print the echo "index of the Variable
";} Public function _ after_index () {// defines the rear Operation echo" index. after
";}Public function list () {// note that the system keyword will return an error echo" list ";}}

OK, an error is reported.
Then configure the suffix


  'Configuration value'/* database settings */'db _ type' => 'mysql', // Database TYPE 'db _ host' => 'localhost ', // server address 'db _ name' => 'jike ', // database NAME 'db _ user' => 'user ', // username 'db _ pwd' => '123', // password 'db _ port' => '123 ', // port 'db _ prefix' => 'jikexueyuan ', // database table PREFIX 'Load _ EXT_CONFIG' => 'user, upload ', /* application settings */'Action _ SUFFIX '=> 'action', // operation method SUFFIX );

Add a suffix to the method of the system keyword


  ";    }    public function index(){//        $config=C('');//        dump($config);        echo "index
"; } public function _after_index(){ echo "index.after
"; } public function listAction(){ echo "list"; }}

OK. I will open the browser again.
Let's think about what will happen.
Yes, it should continue to report errors.
Invalid index operation

However, no error is reported indicating that the index operation is invalid.
And it runs normally.
You can see that the front and rear are also normal ???

Why?
How is it different from the course?
I don't know if I have neglected anything.
I did not find out why I checked it carefully.
Get started

Reply content:

I added a method list.


  ";} Public function index () {// index () method public // echo'
Hello Think php'; // $ config = C (''); // read all configuration items // dump ($ config); // dump () is the ThinkPHP function used to print the echo "index of the Variable
";} Public function _ after_index () {// defines the rear Operation echo" index. after
";}Public function list () {// note that the system keyword will return an error echo" list ";}}

OK, an error is reported.
Then configure the suffix


  'Configuration value'/* database settings */'db _ type' => 'mysql', // Database TYPE 'db _ host' => 'localhost ', // server address 'db _ name' => 'jike ', // database NAME 'db _ user' => 'user ', // username 'db _ pwd' => '123', // password 'db _ port' => '123 ', // port 'db _ prefix' => 'jikexueyuan ', // database table PREFIX 'Load _ EXT_CONFIG' => 'user, upload ', /* application settings */'Action _ SUFFIX '=> 'action', // operation method SUFFIX );

Add a suffix to the method of the system keyword


  ";    }    public function index(){//        $config=C('');//        dump($config);        echo "index
"; } public function _after_index(){ echo "index.after
"; } public function listAction(){ echo "list"; }}

OK. I will open the browser again.
Let's think about what will happen.
Yes, it should continue to report errors.
Invalid index operation

However, no error is reported indicating that the index operation is invalid.
And it runs normally.
You can see that the front and rear are also normal ???

Why?
How is it different from the course?
I don't know if I have neglected anything.
I did not find out why I checked it carefully.
Get started

I wonder if you have understood the error:

For example, if 'Action _ SUFFIX '=> 'act' is set, the Operation Method for accessing the add operation of a module corresponds to the read module class is changed from the original add method to the addAct method.

This means that if you add an Action and no Action after the index, you will find the index method in the actual controller, because the entry file will match whether there is an Action string based on your method name, if it cannot be found, the corresponding method of the string name will be found!
This avoids the public error of special names.

Related Article

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.