Relationship between URL Path Access and Module Controller in ThinkPHP

  • 2021-07-16 02:07:54
  • OfStack

The relationship between URL path access and module controller in ThinkPHP is a very important link in ThinkPHP program development. Mastering this skill skillfully plays a vital role in learning ThinkPHP one step further. The specific analysis is as follows:

Open the Controller page:

UserAction. class. php//Path: admin\ Lib\ Action\ admin here is the directory corresponding to the new project

As we all know, the methods in Action default to Public attributes, and the methods of private attributes cannot be accessed, but the methods of defining private attributes also have their significance.

The significance of defining private methods in it is mainly reflected in that you can write a method related to user modules here, but you don't want the original method to be too bloated. Therefore, we can define a private method to implement it. If the verification specification changes, only one of these methods needs to be changed. You don't have to look for a lot of code.

The sample code is as follows:


class UserAction extends Action{
 function index(){
  echo ' This is the home page ';
 }
 function add(){
  $this->verify();
  echo ' This is the method of writing data to the database ';
 }
 private function verify(){
  echo ' This is the method of validation ';
 }
}

../admin. php/User/add results:


 This is the method of validation. This is the method of writing data to the database 

I hope this article is helpful to everyone's ThinkPHP programming.


Related articles: