我在indexLibAction目录下新建了一个ShowAction.class.php文件。ps:该目录是控制器的目录。
然后这个文件中继承了action这个类。代码如下:
|
1
2
3
4
5
6
7
8
9
|
<?phpclass ShowAction extends Action{ public function abc(){ echo "这是一个测试<br />"; }} ?> |
现在要访问这个页面,就要在url处输入:http://127.0.0.1/index.php?m=show&a=abc

来看一下究竟为何会是这样。
在网站的根目录新建了一个2.php。
内容为:
|
1
2
3
4
5
|
<?phpecho "<pre>";print_r($_GET); ?> |
不传入任何参数的时候是一个空的数组,会输出如下效果:
Array ( )
传参数时就会酱紫,url:http://127.0.0.1/2.php?a=xishaonian&b=helloworld
Array
(
[a] => xishaonian
[b] => helloworld
)
那么我如果那么写:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<?php$control = isset($_GET['m'])?$_GET['m']:'index';$action = isset($_GET['a'])?$_GET['a']:'index';$obj = new $control();$obj->$action();class index{ function index() { echo "this is index"; } function handler() { echo "this is handler"; }} ?> |
我如果要实例化index类然后访问hanler这个方法那么就是:http://127.0.0.1/2.php?m=index&a=handler

