This article will tell you about the tutorial on the controller class in MVC. Through the previous two sections, we know that the program determines the only Moudle, Conttoller, Action through the route class of a single entry file, and finally executes
The code is as follows | Copy code | ||||
|
Executed when the relevant 'Controller' file exists
The code is as follows | Copy code | ||||||||
$controller_tp = $this->_conttoller.'Controller';
|
The code is as follows | Copy code |
$acion_tmp = $this->_action.'Action'; $controller->$acion_tmp(); |
Execute the corresponding action according to the corresponding Action
All Controller classes integrate a common Controller class. In this lesson, we will analyze the public Controller class
/**
* Frontend public class interface
* Implement public part of the code
*/
/**
* This file can only be indexed. php contains
*/
defined("WEB_AUTH") || die("NO_AUTH");
/**
* Contains menu configuration file
*/
The code is as follows | Copy code | ||||||||||||||||
class Controller { public $tpl; public $controller; public $body;//right menu public $_route ; public $html_; public $tpl_;
/* * Constructor */ public function __construct() { $this->init(); }
/* * Initialize variables, top menu and templates */ protected function init() { global $TPL,$route; $this->tpl = $TPL; $this->_route = $route; }
/** * Template variable pass */ protected function diplayTpl() { $this->body || $this->body = $this->_route->getActionName(); $this->tpl->assign("body",$this->body); /*Set the template directory of this controller*/ $this->controller ||$this->controller =$this->_route->getControllerName(); $this->tpl->assign("controller",$this->controller); $this->tpl->display($this->layout); } /** * smarty encapsulation class * @param string $name * @param string $value */ public function assign($name,$value) { $this->tpl->assign($name,$value); }
/** * Show additional templates * @param string $name * @param string $value */ protected function displayOther($file) { $this->assign("otherTpl",TRUE); $this->tpl->display($file); } /** * Display the body template of a certain MCA * 0=>m 1=>c =>a */ protected function getMcaBody($array) { return 'http://www.cnblogs.com/../'.$array[0].'/body/'.$array[1].'/'.$array[2]; } /* * Destructor, display page */ protected function __destruct() { $this->tpl->_tpl_vars['otherTpl'] || $this->diplayTpl(); } /** * Exit midway */ protected function _exit($msg = "") { $this->assign("otherTpl",TRUE); die($msg); }
/** * Use $this->html_var=value to assign a value to the variable * Use $this->tpl_var=value to assign a value to the variable */ protected function __set($name,$value) { if(strtolower(substr($name,0,5)) == "html_" || strtolower(substr($name,0,4)) == "tpl_") { $this->assign(substr($name,5),$value); } } } ?> 首先看
Previous article:PHP object-oriented abstract methods and abstract classes __call detailed tutorial on cloning objects_PHP tutorial
Next article:Use of PHP object-oriented static, const, and final keywords_PHP tutorial
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|