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

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

  • 相关阅读:
    对于在git上面拉代码报"error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054"解决方法
    在vue项目中如何添加eslint
    vscode编辑如何保存时自动校准eslint规范
    css3动画
    JS中的深拷贝与浅拷贝
    JS中的防抖与节流
    金三银四求职季,前端面试题小梳理(HTML、CSS、JS)
    正则表达式元字符大整理
    常规正则表达式练习,一起来开心的掉发吧
    关于子元素的margin-top对父级容器无效
  • 原文地址:https://www.cnblogs.com/kudosharry/p/3768158.html
Copyright © 2011-2022 走看看