zoukankan      html  css  js  c++  java
  • yaf框架流程三

    路由的原理请看http://yaf.laruence.com/manual/yaf.routes.html这个链接

    要点:路由的顺序是堆栈模式的,及最后添加的路由规则最优先。由上两篇可知,定义的第一条路由是application实例化时候的new Yaf_Route_Static()。

    然后在bootstrap里有初始化路由的操作,主要方法是:
    1.从配置添加

    $routes = $this->config->routes;
    $router = $dispatcher->getRouter();
    $router->addConfig($routes);


    2.语句添加
    $route = new Yaf_Route_Rewrite(
    "/product/list/:id/:name",
    array(
    "controller" => "product",
    "action" => "info",
    )
    );

    $router->addRoute('dummy', $route);

    通过$dispatcher->getRouter()->getRoutes()可以查看到

    array (size=7)
      '_default' => 
        object(Yaf_Route_Static)[6]
      'index' => 
        object(Yaf_Route_Regex)[12]
          protected '_route' => string '#^/([a-zA-Z]+)/?#' (length=17)
          protected '_default' => 
            array (size=3)
              'module' => string 'Index' (length=5)
              'controller' => string 'Index' (length=5)
              'action' => string 'Index' (length=5)
          protected '_maps' => 
            array (size=1)
              1 => string 'name' (length=4)
          protected '_verify' => 
            array (size=3)
              'module' => string 'Index' (length=5)
              'controller' => string 'Index' (length=5)
              'action' => string 'Index' (length=5)
          protected '_reverse' => null
      'regex' => 
        object(Yaf_Route_Regex)[13]
          protected '_route' => string '#^list/([^/]*)/([^/]*)#' (length=23)
          protected '_default' => 
            array (size=2)
              'controller' => string 'Index' (length=5)
              'action' => string 'action' (length=6)
          protected '_maps' => 
            array (size=2)
              1 => string 'name' (length=4)
              2 => string 'value' (length=5)
          protected '_verify' => 
            array (size=2)
              'controller' => string 'Index' (length=5)
              'action' => string 'action' (length=6)
          protected '_reverse' => null
      'simple' => 
        object(Yaf_Route_Simple)[14]
          protected 'controller' => string 'c' (length=1)
          protected 'module' => string 'm' (length=1)
          protected 'action' => string 'a' (length=1)
      'supervar' => 
        object(Yaf_Route_Supervar)[15]
          protected '_var_name' => string 'r' (length=1)
      'rewrite' => 
        object(Yaf_Route_Rewrite)[16]
          protected '_route' => string '/product/:name/:value' (length=21)
          protected '_default' => 
            array (size=2)
              'controller' => string 'product' (length=7)
              'action' => string 'info' (length=4)
          protected '_verify' => 
            array (size=2)
              'controller' => string 'product' (length=7)
              'action' => string 'info' (length=4)
          protected '_reverse' => null
      'dummy' => 
        object(Yaf_Route_Rewrite)[17]
          protected '_route' => string '/product/list/:id/:name' (length=23)
          protected '_default' => 
            array (size=2)
              'controller' => string 'product' (length=7)
              'action' => string 'info' (length=4)
          protected '_verify' => null
          protected '_reverse' => null

    可以看出保存为一个数组,顺序与配置的顺序一致,语句最后添加的也在最后。

  • 相关阅读:
    程序员深夜惨遭老婆鄙视,原因竟是CAS原理太简单?| 每一张图都力求精美
    微前端大赏
    【老李瞎折腾】001、折腾一下DDNS
    【老李瞎折腾】000、使用树莓派搭建自己的服务器
    【老李瞎折腾】目录
    RGB打水印在YUV图片上
    BMP格式解析
    测试开发不会前端?ElementUI你需要了解一下
    如何通过命令行运行Postman脚本2020-09-15
    长点心吧!测试老鸟教你如何避免背锅
  • 原文地址:https://www.cnblogs.com/kudosharry/p/3768158.html
Copyright © 2011-2022 走看看