zoukankan      html  css  js  c++  java
  • thinkphp3.2.3中设置路由,优化url

    需求: 访问这个目录的时候,http://xx.com/p-412313要重定向到(暂且这么叫)http://xx.com/Home/Blog/index/id/412313

    就是看着好看

    我的应用目录是Application。模块是Home

    第一步:知道哪个文件怎么处理的路由
    路由处理在think/Route.class.php

    1. // 动态路由处理  
    2.         $routes =   C('URL_ROUTE_RULES');  
    3.         // var_dump($routes);  
    4.   
    5.         if(!empty($routes)) {  
    6.             // dump($routes);  
    7.             //array(1) {  
    8.                 // ["/^p-(d+)$/"] => string(16) "Blog/index?id=:1"  
    9.             //}  
    10.             // echo "rount.class.php ";  
    11.             foreach ($routes as $rule=>$route){  
    12.                 if(is_numeric($rule)){  
    13.                     // 支持 array('rule','adddress',...) 定义路由  
    14.                     $rule   =   array_shift($route);  
    15.                 }  
    16.      ...代码多,仅标识位置  


    第二步:在项目模块的配置文件下,设置配置文件 如下(因为tp是逐级加载配置文件,惯例配置->应用配置->模式配


    置->调试配置->状态配置->模块配置->扩展配置->动态配置,这里属于模块配置

    1. <?php  
    2. return array(  
    3.   
    4.   
    5.     'MODULE_ALLOW_LIST' => array('Home','Admin','Common'),  
    6.      'DEFAULT_MODULE'       =>    'Home',  // 默认模块  
    7.      'DEFAULT_CONTROLLER'    =>  'Index', // 默认控制器名称  
    8.      'DEFAULT_ACTION'        =>  'index', // 默认操作名称  
    9.          //    路由规则  
    10.     'URL_ROUTER_ON' => TRUE,  
    11.     'URL_ROUTE_RULES' => array(  
    12.         '/^c-(d+)$/' => 'Index/content?id=:1'  
    13.     ),  
    14.      'URL_ROUTER_ON '=>true,  
    15.      'URL_MODEL'          => '1',  
    16.   
    17.      'URL_ROUTE_RULES'=>array(     
    18.        '/^p-(d+)$/' => 'Home/Blog/index?id=:1',//意思是访问x.com/p-34 会访问的是x.com/Blog/index/id/34  
    19.   
    20.          ),  
    21. );  


    第三部:
    如果你没有设置默认的模块 ,会出现找不到p-34这个模块的错误。
    那么需要在index.php中设置
    define('BIND_MODULE','Home');

    这样就可以了。

    说明:如果没有第三步。默认打开是正常的就是这样。

    但是

    所以我们操作第三步,就可以实现如下效果了:

  • 相关阅读:
    《DSP using MATLAB》Problem 6.17
    一些老物件
    《DSP using MATLAB》Problem 6.16
    《DSP using MATLAB》Problem 6.15
    《DSP using MATLAB》Problem 6.14
    《DSP using MATLAB》Problem 6.13
    《DSP using MATLAB》Problem 6.12
    《DSP using MATLAB》Problem 6.11
    P1414 又是毕业季II
    Trie树
  • 原文地址:https://www.cnblogs.com/lxwphp/p/9203691.html
Copyright © 2011-2022 走看看