search
HomeBackend DevelopmentPHP TutorialUnderstanding MVC Programming Controllers in PHP_PHP Tutorial
Understanding MVC Programming Controllers in PHP_PHP TutorialJul 13, 2016 pm 05:32 PM
mvcphpeffectuseitacceptcontrollerunderstandofSimpleprogrammingask

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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么设置implode没有分隔符php怎么设置implode没有分隔符Apr 18, 2022 pm 05:39 PM

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php怎么去除首位数字php怎么去除首位数字Apr 20, 2022 pm 03:23 PM

去除方法:1、使用substr_replace()函数将首位数字替换为空字符串即可,语法“substr_replace($num,"",0,1)”;2、用substr截取从第二位数字开始的全部字符即可,语法“substr($num,1)”。

php有操作时间的方法吗php有操作时间的方法吗Apr 20, 2022 pm 04:24 PM

php有操作时间的方法。php中提供了丰富的日期时间处理方法:1、date(),格式化本地日期和时间;2、mktime(),返回日期的时间戳;3、idate(),格式化本地时间为整数;4、strtotime(),将时间字符串转为时间戳等等。

php怎么去掉右边几个字符php怎么去掉右边几个字符Apr 21, 2022 pm 07:45 PM

去掉方法:1、用substr_replace()删除右边n位置开始的全部字符,语法“substr_replace($str,"",-n)”,参数“n”为需要去除的字符个数;2、用substr(),语法“substr($str,0,-n)”。

php怎么给数组增加一个数组元素php怎么给数组增加一个数组元素Apr 19, 2022 pm 08:45 PM

增加元素的方法:1、使用“array_unshift(数组,数组元素)”语句,在数组的开头添加元素;2、使用“array_push(数组,数组元素)”语句,在数组的末尾添加元素;3、用“array_pad(数组,数组长度+1,元素)”语句。

php怎么去掉数组键值php怎么去掉数组键值Apr 20, 2022 pm 05:12 PM

php去掉数组键值的方法:1、使用“array_keys($array)”语句,可去掉全部键值,返回包含全部键名的数组;2、使用“array_splice($array,$start,$length)”语句,可去掉指定位置的一个或多个键值。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

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.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use