php yaf框架中路由器问题

 倪好蛋蛋小猪 发布于 2022-11-14 22:24
    $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')));

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

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

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

4 个回答
  • 很奇怪,难道不看手册的吗?

    8.5. 路由协议详解

    2022-11-14 22:56 回答
  • 问题1

     $route  = new Yaf_Route_Rewrite(
                            "/product/list/:id/",
                            array(
                                    "controller" => "product",
                                    "action"         => "info",
                            )
                    );
    
                    $router->addRoute('dummy', $route);

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

    如果在ini中添加

    [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'

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

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

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

    2022-11-14 22:56 回答
  • 可以邮件 鸟哥, 他这yaf框架的核心开发者之一。

    2022-11-14 22:56 回答
  • 不用yaf,但路由相关的是知道一点的。

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

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

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

    2022-11-14 22:56 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有