跟着百度学习php之ThinkPHP的运行流程-1
我在index\Lib\Action\目录下新建了一个ShowAction.class.php文件。ps:该目录是控制器的目录。
然后这个文件中继承了action这个类。代码如下:
<?php 
class ShowAction extends Action
{
	public function abc(){
		echo "这是一个测试<br />";
	}
}
 ?>
现在要访问这个页面,就要在url处输入:http://127.0.0.1/index.php?m=show&a=abc

来看一下究竟为何会是这样。
在网站的根目录新建了一个2.php。
内容为:
<?php echo "<pre>"; print_r($_GET); ?>
不传入任何参数的时候是一个空的数组,会输出如下效果:
Array
(
)
传参数时就会酱紫,url:http://127.0.0.1/2.php?a=xishaonian&b=helloworld
Array
(
    [a] => xishaonian
    [b] => helloworld
)
那么我如果那么写:
<?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


By:珍惜少年时博客:http://www.cnblogs.com/xishaonian/
*-------------------------------------------*
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号