我在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

跟着百度学习php之ThinkPHP的运行流程-1

来看一下究竟为何会是这样。

在网站的根目录新建了一个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

跟着百度学习php之ThinkPHP的运行流程-1

跟着百度学习php之ThinkPHP的运行流程-1

 

相关文章:

  • 2021-12-26
  • 2021-10-07
  • 2021-07-15
  • 2021-07-08
  • 2021-07-23
  • 2021-07-20
  • 2021-11-02
  • 2021-07-02
猜你喜欢
  • 2021-12-06
  • 2021-05-23
  • 2022-02-07
  • 2021-06-07
  • 2021-06-17
  • 2021-06-21
相关资源
相似解决方案