The role of the controller is usually to obtain the data in the model and give it to the view to display. So how should we write it during development?
1. Create the class file of Controller. My file name is MatchController.class.php (recommended learning: Getting Started with PHP Programming To master)
<?php/** * 比赛操作相关控制器功能类 */class MatchController{ /** * 比赛列表操作 */ public function listAction(){ header('Content-Type: text/html;charset=utf-8'); //实例化相应的模型类对象,调用某个方法,实现固定功能 // require './MatchModel.class.php'; // $m_match = new MatchModel(); //通过工厂获得对象 require './Factory.class.php'; $m_match = Factory::M('MatchModel'); $match_list = $m_match->getList(); // $m_match2 = Factory::M('MatchModel'); // 载入负责显示的html文件 require './template/match_list_v.html'; } /** * 比赛删除 */ public function removeAction(){ }
2. Instantiate the controller object (front-end controller or request dispatcher) in the entry file, the file name is index.php
In order to allow index.php to perform the actions we want to operate, some parameters should be passed to index.php to tell the entry file how to do it.
If we want to delete a game information in the game list (Game Controller), we can pass the parameters to index.php like this:
index.php?c=match&a=remove&id=N
The corresponding HTML file should be written like this:
index.php:
<?php //动作 $default_action = 'list'; $a = isset($_GET['a'])?$_GET['a']:$default_action; //实例化控制器类 require './MatchController.class.php'; //实例化 $controller = new MatchController(); //调用方法 $action_name = $a.'Action'; $controller -> $action_name();//可变方法
The above is the detailed content of Where are the methods of the php controller?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor
