php yaf架構中路由器問題

來源:互聯網
上載者:User
    $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')))
三個參數各表示什麼(尤其是第一個,強烈表示不解。。)?怎麼理解這個路由(就是三個參數怎麼協調的)?

回複內容:

    $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')))
三個參數各表示什麼(尤其是第一個,強烈表示不解。。)?怎麼理解這個路由(就是三個參數怎麼協調的)?

不用yaf,但路由相關的是知道一點的。

  • 參數1,匹配請求地址中的URI部分。例如:http://www.baidu.com/mobile,那麼這個uri就是mobile,對應到你寫的路由就第一個參數。

  • 參數2,是數組,controller對應的值是控制器,action是對應的方法。

  • 參數3,也是數組,是請求帶過去的參數,例如,page是第幾頁呀等等。

可以郵件 鳥哥, 他這yaf架構的核心開發人員之一。

問題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:這問題如果你去問鳥哥,鳥哥心情好的話會拋給你一份鳥哥語錄。

很奇怪,難道不看手冊的嗎?

8.5. 路由協議詳解

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.