zoukankan      html  css  js  c++  java
  • 跟着百度学习php之ThinkPHP的运行流程-1

    我在indexLibAction目录下新建了一个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

  • 相关阅读:
    nginx解决跨域问题
    SSM整合相关试题
    SSM整合案例--用户登录
    非法用户登录拦截
    SpringMVC拦截器和数据校验
    SpringMVC文件上传
    SpringMVC异常处理
    SpringMVC方法的返回值类型和自动装配
    SpringMVC
    spring和mybatis整合
  • 原文地址:https://www.cnblogs.com/xishaonian/p/6753859.html
Copyright © 2011-2022 走看看