php yaf框架中路由器问题

php中文网
发布: 2016-08-18 09:15:56
原创
1787人浏览过

<code>    $router->addRoute('html', new Yaf_Route_Regex('/([a-z]+)\.html$/', array('controller' => 'Index', 'action' => 'html'), array(1 => 'page')));
    $router->addRoute('security', new Yaf_Route_Rewrite('security/:name/:rout', array('controller' => 'Security', 'action' => 'html')));
    $router->addRoute('trade', new Yaf_Route_Rewrite('trade/:name/:rout', array('controller' => 'Trade', 'action' => 'html')));
</code>
登录后复制

问题一:addroute第一个参数是后面添加路由的名字么?

问题二:Yaf_Route_Regex('/([a-z]+).html$/', array('controller' => 'Index', 'action' => 'html'), array(1 => 'page')))
三个参数各表示什么?怎么理解这个路由(就是三个参数怎么协调的)?

立即学习PHP免费学习笔记(深入)”;

问题三:Yaf_Route_Rewrite('security/:name/:rout', array('controller' => 'Security', 'action' => 'html')))
三个参数各表示什么(尤其是第一个,强烈表示不解。。)?怎么理解这个路由(就是三个参数怎么协调的)?

回复内容:

<code>    $router->addRoute('html', new Yaf_Route_Regex('/([a-z]+)\.html$/', array('controller' => 'Index', 'action' => 'html'), array(1 => 'page')));
    $router->addRoute('security', new Yaf_Route_Rewrite('security/:name/:rout', array('controller' => 'Security', 'action' => 'html')));
    $router->addRoute('trade', new Yaf_Route_Rewrite('trade/:name/:rout', array('controller' => 'Trade', 'action' => 'html')));
</code>
登录后复制

问题一:addroute第一个参数是后面添加路由的名字么?

问题二:Yaf_Route_Regex('/([a-z]+).html$/', array('controller' => 'Index', 'action' => 'html'), array(1 => 'page')))
三个参数各表示什么?怎么理解这个路由(就是三个参数怎么协调的)?

立即学习PHP免费学习笔记(深入)”;

问题三:Yaf_Route_Rewrite('security/:name/:rout', array('controller' => 'Security', 'action' => 'html')))
三个参数各表示什么(尤其是第一个,强烈表示不解。。)?怎么理解这个路由(就是三个参数怎么协调的)?

不用yaf,但路由相关的是知道一点的。

  • 参数1,匹配请求地址中的URI部分。例如:http://www.baidu.com/mobile,那么这个uri就是mobile,对应到你写的路由就第一个参数。

  • 参数2,是数组,controller对应的值是控制器,action是对应的方法。

  • 参数3,也是数组,是请求带过去的参数,例如,page是第几页呀等等。

    BetterYeah AI
    BetterYeah AI

    基于企业知识库构建、训练AI Agent的智能体应用开发平台,赋能客服、营销、销售场景 -BetterYeah

    BetterYeah AI 110
    查看详情 BetterYeah AI

可以邮件 鸟哥, 他这yaf框架的核心开发者之一。

问题1

<code> $route  = new Yaf_Route_Rewrite(
                        "/product/list/:id/",
                        array(
                                "controller" => "product",
                                "action"         => "info",
                        )
                );

                $router->addRoute('dummy', $route);</code>
登录后复制

如果这样添加,名字无所谓,

如果在ini中添加

<code>[routes]
routes.product.type='regex'
routes.product.match='#^/([0-9]+)[\/]?$#'
routes.product.route.module='Product'
routes.product.route.controller='product'
routes.product.route.action='show'
routes.product.map.1='pid'</code>
登录后复制

这样需要读取配置,然后初始化路由
实际上他的名字可以参考路由的5种方式。simplle supervar static【默认】 map rewirte regex

问题2 问题 3 我想你已经知道答案了

tips:这问题如果你去问鸟哥,鸟哥心情好的话会抛给你一份鸟哥语录。

很奇怪,难道不看手册的吗?

8.5. 路由协议详解

相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号