search
Homephp教程php手册phpcms(1)phpcms V9 MVC模式 与 URL访问解析(转),phpcmsmvc

phpcms(1)phpcms V9 MVC模式 与 URL访问解析(转),phpcmsmvc

【1】URL访问解析

观察访问网页时的网址,可以得出模块访问方法,如下示例:

http://www.abcd.com.cn/phpcms/index.php?m=content&c=index&a=show&id=1

关于此URL解析如下:

m = content 为模块/模型名称 位于phpcms/modules/content (必须项

c = index 为控制器名称 位于phpcms/modules/content/index.php (必须项

a = show 为事件名称 位于phpcms/modules/content/index.php 中的show方法

id = 1 为其他参数 与正常get传递参数形式相同 

那么,问题来了!我们经常访问首页的网址为:http://www.abcd.com.cn/phpcms/index.php 为什么没有m和c的值呢?

这里解释一下,系统在没有指定模块和控制器的时候,会执行默认的模块和操作。如上的网址,PHPCMS默认路由会定位到content模块的index控制器中的init操作。因此与下面的URL结果是相同的:

http://www.abcd.com.cn/phpcms/index.php?m=content&c=index&a=init

系统还支持URL路由的功能,这些都能够带来其他的url访问效果。

其路由文件位于 phpcms\caches\configs\route.php 内容整理如下所示:

 1 <?php
 2 /**
 3  * 路由配置文件
 4  * 默认配置为default如下:
 5  * 'default'=>array(
 6  *     'm'=>'phpcms', 
 7  *     'c'=>'index', 
 8  *     'a'=>'init', 
 9  *     'data'=>array(
10  *         'POST'=>array(
11  *             'catid'=>1
12  *             ),
13  *         'GET'=>array(
14  *             'contentid'=>1
15  *             )
16  *         )
17  * )
18  * 其中“m”为模型,“c”为控制器,“a”为事件,“data”为其他附加参数。
19  * data为一个二维数组,可设置POST和GET的默认参数。
20  * POST和GET分别对应PHP中的$_POST和$_GET两个超全局变量。
21  * 在程序中你可以使用$_POST['catid']来得到data下面POST中的数组的值。
22  * data中的所设置的参数等级比较低。如果外部程序有提交相同的名字的变量,将会覆盖配置文件中所设置的值。
23  * 如:外部程序POST了一个变量catid=2那么你在程序中使用$_POST取到的值是2,而不是配置文件中所设置的1。
24  */
25 return array(
26     'default'=>array('m'=>'content', 'c'=>'index', 'a'=>'init'),
27 );

为了更具体的理解,简单实例如下:

1. 在phpcms/modules目录下,新建一个文件夹,命名为demo,即模块名为demo

2. 在demo文件夹中,新建一个文本文件,命名为test,修改文件类型为php。用Notepad++打开test文件,编辑内容如下:

1 <?php
2     class test
3     {
4         public function show()
5         {
6             echo "I Love PHPCMS V9.";
7         }
8     }
9 ?>

注意:test.php里面的内容,必须要用class类的写法,否则会提示control找不到,即mvc中的c找不到。如果没有指定a,则调用init方法,如果没有实现init方法,则会显示:Action does not exist。

3. 在浏览器的网址栏输入:http://localhost/phpcms/index.php?m=demo&c=test&a=show 回车 结果如下图:

【2】模块

phpcms V9框架中的模块,位于phpcms/modules目录中,每一个目录称为一个模块。即上文URL访问中的m。

如果需要创建一个模块,只要在phpcms/modules目录下创建文件夹并放入你的控制器类就可以了。

【3】控制器

关于控制器类,可以参见文章《phpcms V9 添加模块》

Good Good Study, Day Day Up.

顺序  选择  循环  总结

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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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.