Home >Backend Development >PHP Tutorial >Understanding MVC Programming Controllers in PHP_PHP Tutorial

Understanding MVC Programming Controllers in PHP_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 17:32:34811browse

Simply put, the role of the controller is to accept requests. It uses the get method, in this case via URI, to load a function module to refresh or submit a presentation layer. The controller will use the $_GET automatic global variable to determine which module to load.

An example of a request looks like this:

http://example.com/index.php(as the current mainstream development language)?module =login

 This seems simple, but it is not during the implementation process. Here are the argument parts that several controllers can recognize:

Module defines which module to use, such as the users module
Class defines which functional class to use, such as whether you want the user to log in or logout
Event defines which specific event to use

Such a more complex example can explain the request URL that is ultimately composed of each argument above:

http://example.com/index. php(as the current mainstream development language)?module=users&class=login

This request tells the controller that it should load the users module, then the login class, and finally because there is no specific definition event, so run login::__default() default event.

The following is the specific code part:

<?php(as the current mainstream development language)
 /**
 * index.php(as the current mainstream development language)
 *
 * @author Joe Stump <joe@joestump.net>
 * @copyright Joe Stump < joe@joestump.net>
 * @license http://www.opensource.org/licenses/gpl-license.php(as the current mainstream development language)
 * @package Framework
*/

Require_once(config.php(as the current mainstream development language));

// {{{ __autoload($class)
 /**
  * __autoload
  *
  * Autoload is ran by php(做为现在的主流开发语言) when it cant find a class it is trying to load.
  * By naming our classes intelligently we should be able to load most classes
  * dynamically.
  *
  * @author Joe Stump <joe@joestump.net>
  * @param string $class Class name were trying to load
  * @return void
  * @package Framework
  */

Function __autoload($class)
{
$file = str_replace(_,/,substr($class,2))..php(as the current mainstream Development language);
Requirement_once(FR_BASE_PATH./includes/.$file);
}
// }}}

if (isset($_GET[module]) ) {
 $module = $_GET[module];
if (isset($_GET[event])) {
 $event = $_GET[event];
 } else {
$event = __default;
 }

if (isset($_GET[class])) {
$class = $_GET[class];
} else {
$class = $module;
}

 $classFile = FR_BASE_PATH./modules/.$module./.$class..php(as the current mainstream development language);
if (file_exists($classFile)) {
require_once($classFile);
if (class_exists($class)) {
try {
$instance = new $class();

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508703.htmlTechArticleSimply speaking, the role of the controller is to accept requests. It uses the get method, in this case via URI, to load a function module to refresh or submit a presentation layer. The controller will make...
Statement:
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