Home >Backend Development >PHP Problem >what does php controller mean
php controller refers to C in MVC, that is, Controller. The function of its controller is usually to obtain the data in the model (Model) and give it to the view (View) for display.
#The operating environment of this article: Windows7 system, PHP7.1, Dell G3.
What does php controller mean?
Implementation of the Controller layer in PHP
The role of the Controller is usually to obtain and exchange data in the Model. Let the View display it, so how should we write it during development?
<?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(){ } }
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();//可变方法
Recommended learning: " PHP video tutorial》
The above is the detailed content of what does php controller mean. For more information, please follow other related articles on the PHP Chinese website!