当前位置:网站首页>thinkphp3.2.3中设置路由,优化url
thinkphp3.2.3中设置路由,优化url
2022-07-07 14:06:00 【全栈程序员站长】
需求: 访问这个目录的时候,http://xx.com/p-412313要重定向到(暂且这么叫)http://xx.com/Home/Blog/index/id/412313
就是看着好看
我的应用目录是Application。模块是Home
第一步:知道哪个文件怎么处理的路由 路由处理在think/Route.class.php
- // 动态路由处理
- $routes = C(‘URL_ROUTE_RULES’);
- // var_dump($routes);
- if(!empty($routes)) {
- // dump($routes);
- //array(1) {
- // [“/^p-(\d+)$/”] => string(16) “Blog/index?id=:1”
- //}
- // echo “rount.class.php\n”;
- foreach (routes as rule=>
- if(is_numeric($rule)){
- // 支持 array(‘rule’,’adddress’,…) 定义路由
- rule = array_shift(route);
- }
- …代码多,仅标识位置
第二步:在项目模块的配置文件下,设置配置文件 如下(因为tp是逐级加载配置文件,惯例配置->应用配置->模式配
置->调试配置->状态配置->模块配置->扩展配置->动态配置,这里属于模块配置
- <?php
- return array(
- ‘MODULE_ALLOW_LIST’ => array(‘Home’,‘Admin’,‘Common’),
- ‘DEFAULT_MODULE’ => ‘Home’, // 默认模块
- ‘DEFAULT_CONTROLLER’ => ‘Index’, // 默认控制器名称
- ‘DEFAULT_ACTION’ => ‘index’, // 默认操作名称
- // 路由规则
- ‘URL_ROUTER_ON’ => TRUE,
- ‘URL_ROUTE_RULES’ => array(
- ‘/^c-(\d+)$/’ => ‘Index/content?id=:1’
- ),
- ‘URL_ROUTER_ON ‘=>true,
- ‘URL_MODEL’ => ‘1’,
- ‘URL_ROUTE_RULES’=>array(
- ‘/^p-(\d+)$/’ => ‘Home/Blog/index?id=:1’,//意思是访问x.com/p-34 会访问的是x.com/Blog/index/id/34
- ),
- );
第三部: 如果你没有设置默认的模块 ,会出现找不到p-34这个模块的错误。 那么需要在index.php中设置 define(‘BIND_MODULE’,’Home’);
这样就可以了。
说明:如果没有第三步。默认打开是正常的就是这样。
但是
所以我们操作第三步,就可以实现如下效果了:
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113178.html原文链接:https://javaforall.cn
边栏推荐
- Learn good-looking custom scroll bars in 1 minute
- 分步式監控平臺zabbix
- Three. JS introductory learning notes 04: external model import - no material obj model
- Wireless sensor networks -- ZigBee and 6LoWPAN
- Shader basic UV operations, translation, rotation, scaling
- torch.numel作用
- What else can an ordinary person do besides working in a factory to make money?
- Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
- Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
- Three. JS introductory learning notes 18: how to export JSON files with Blender
猜你喜欢

Logback logging framework third-party jar package is available for free

Xingruige database was shortlisted as the "typical solution for information technology application and innovation in Fujian Province in 2021"
Notification uses full resolution

20th anniversary of agile: a failed uprising

保证接口数据安全的10种方案
![Application example of infinite list [uigridview]](/img/11/3be1c63680e6de8f068e79690ecf12.jpg)
Application example of infinite list [uigridview]

numpy--疫情数据分析案例

Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc

Leetcode-231-2的幂

航运船公司人工智能AI产品成熟化标准化规模应用,全球港航人工智能/集装箱人工智能领军者CIMC中集飞瞳,打造国际航运智能化标杆
随机推荐
It's different for rich people to buy a house
AE learning 02: timeline
js中复选框checkbox如何判定为被选中
Logback日志框架第三方jar包 免费获取
laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配
Unity的三种单例模式(饿汉,懒汉,MonoBehaviour)
JS array foreach source code parsing
Communication mode between application program and MATLAB
L'application à l'échelle de la normalisation mature des produits ai des compagnies maritimes, cimc, leader mondial de l'intelligence artificielle portuaire et maritime / intelligence artificielle des
nodejs package. JSON version number ^ and~
模仿企业微信会议室选择
Talk about the cloud deployment of local projects created by SAP IRPA studio
Please supervise the 2022 plan
Leetcode-231-2的幂
Excessive dependence on subsidies, difficult collection of key customers, and how strong is the potential to reach the dream of "the first share of domestic databases"?
Three. JS introductory learning notes 0: illustration of how webgl and threejs work
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
尤雨溪,来了!
Three. JS introductory learning notes 15: threejs frame animation module