Simply put, the controller is used to accept requests. It uses the obtained method. Here, a function module is loaded through URI to refresh or submit a presentation layer. The controller uses 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 mainstream development language )? Module = login
This seems simple, but not in the implementation process. Here is the argument part that several controllers can recognize:
Module defines which module to use, such as the users module
Class defines which function class to use, such
Event defines which specific event to use
In this more complex example, we can explain the final request URL composed of each argument:
Http://example.com/index.php (as the mainstream development language )? Module = users & class = login
This request tells the Controller to load the users module, followed by the login class, and finally runs the default login :__ default () event because no specific event is defined.
The Code is as follows:
<? Php (as the mainstream development language)
/**
* Index. php (as the mainstream development language)
*
* @ Author jostump <joe@joestump.net>
* @ Copyright jostump <joe@joestump.net>
* @ License http://www.opensource.org/licenses/gpl-license.php (as the mainstream development language)
* @ Package Framework
*/
Require_once (config. php (as the mainstream development language ));
// {_ Autoload ($ class)
/**
* _ Autoload
*
* Autoload is ran by php (as the mainstream development language) when it cant find a class it is trying to load.
* By naming our classes intelligently we shoshould be able to load most classes
* Dynamically.
*
* @ Author jostump <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 mainstream development language );
Require_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 mainstream development language );
If (file_exists ($ classFile )){
Require_once ($ classFile );
If (class_exists ($ class )){
Try {
$ Instance = new $ class ();