controller & view
| OK PATTERN | NG PATTERN |
| User action ↓ controller ↓ view |
User action ↓ view |
| ① User action ↓ ② Methods of controller(Example:action_index) ↓ ③view(Example:index.php) |
*Whenever a user operates it, it goes to the controller.
Process
① User operation
② Methods of controller(Example: action_index)
③ view(Example:index.php)
The function in the controller is executed by the user.
The operation here refers to jumping to the “domain name/controller name/function name” link.
Pattern 2: as the destination of the form tag
Execute the functions in the controller.
First, since “index.php” is a list page, it retrieves the information necessary to display the list page.
In this example, since the list page simply refers to the registered data
The “get data registered in the database” process is performed.
Next, “calling the view” processing is required.
Instead of sending to the view file, think of it as “calling the view in the include.
The index.php (view) file is called.
This is where the page is loaded for the first time for the user to see.
The data to be displayed here is the data obtained from the controller.
The data to be displayed here is the data obtained from the controller, so it would not be possible without the controller.
supplement
Unlike the popular MVC model, we develop our products using CV.
In the case of MVC
M: Data handling
V: Display
C: Control of processing
In case of CV
C: Control of processing / handling of data
V: Display
You can get the DB table information in the view and display it, but you can also get the DB table information in the controller and display it in the view.
Basically, use controller to retrieve DB table information and display it in view.
page transition
| include ※page view |
File reading is done using the include_once function, which reads the files contained in the view file. include_once(dirname(__FILE__) . “/../view/customer_list.php”); |
| redirect ※page transition |
File transitions can be made using the redirectUrl function and transitions can be made.
redirectUrl(‘customer/list’); |
