zoukankan      html  css  js  c++  java
  • thinkphp5在URL地址里隐藏模块名

    新的Thinkphp5的路由功能很强大,完全可以自定义以满足自己的要求
     
    ThinkPHP5.0的路由规则如下:http://serverName/index.php/module/controller/action/param/value/...
     

    我们不仅可以通过Apache的.htaccess配置文件在url中隐藏index.php
    还可以通过以下自定义路由配置隐藏控制名,以达到URL更简短的效果
     
    你的route.php配置如下
    <?php
        /*
        * @Author: huangyuan
        * @Date: 2017-03-01 14:39:37
        * @Last Modified by:   huangyuan413026@163.com
        * @Last Modified time: 2017-03-01 14:39:37
        * @Description: 路由配置,在URL中隐藏模块名
        */
        return [
            //默认首页
            ''=>'index/index',
            
            //未隐藏模块名 http://tp5.com/index/5 
            // 'index:name'=>['index/hello',['name'=>'w+']],
            //隐藏模块名 http://tp5.com/5 
            ':name'=>['index/hello',['name'=>'w+']],
            // 路由分组
            '[]'=>[
                ':id'=>['index/who',['id'=>'d+']]
                // ':name'=>['index/hello',['name'=>'w+']],
            ]
        ];
    

      

     
    application/index/controller/index.php
    <?php
    /*
     * @Author: huangyuan
     * @Date: 2017-03-01 14:39:11
     * @Last Modified by: huangyuan413026@163.com
     * @Last Modified time: 2017-03-01 14:39:34
     */
    namespace appindexcontroller;
    class Index
    {
    	public function index()
    	{
    		echo '<br>This is the index method';
    	}
    	
    	public function who($id){
    		echo $id;
    		echo '<br>This is the who method';
    	}
    	public function hello($name){
    		echo $name;
    		echo '<br>This is the hello method';
    	}
    }
    

      

    index action
    who action
    hello方法
     
    通过模块访问则会进入index action
    参考:
     
     
     
     



  • 相关阅读:
    企业级 SpringBoot 教程 (九)springboot整合Redis
    03 网格系统
    02 表单
    01 排版
    客户端调用webSerices
    sql 一行转多行
    sql 多行转一行
    时间差计算 Stopwatch
    sql 游标
    Linq连接查询
  • 原文地址:https://www.cnblogs.com/huangtailang/p/6484277.html
Copyright © 2011-2022 走看看