略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Yaf_Router::addConfig

2024-12-22

Yaf_Router::addConfig

(Yaf >=1.0.0)

Yaf_Router::addConfig向Router中添加配置文件中定义的路由

说明

public Yaf_Router::addConfig(Yaf_Config_Abstract $config): void

将application.ini中定义的路由规则添加到Yaf_Router的路由栈中

警告

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

范例

示例 #1 application.ini()example

;the order is very important, the prior one will be called first

;a rewrite route match request /product/*/*
routes.route_name.type="rewrite"
routes.route_name.match="/product/:name/:value"
routes.route_name.route.controller=product
routes.route_name.route.action=info

;a regex route match request /list/*/*
routes.route_name1.type="regex"
routes.route_name1.match="#^list/([^/]*)/([^/]*)#"
routes.route_name1.route.controller=Index
routes.route_name1.route.action=action
routes.route_name1.map.1=name
routes.route_name1.map.2=value

;a simple route match /**?c=controller&a=action&m=module
routes.route_name2.type="simple"
routes.route_name2.controller=c
routes.route_name2.module=m
routes.route_name2.action=a

;a simple router match /**?r=PATH_INFO
routes.route_name3.type="supervar"
routes.route_name3.varname=r

;a map route match any request to controller
routes.route_name4.type="map"
routes.route_name4.controllerPrefer=TRUE
routes.route_namer.delimiter="#!"

示例 #2 Yaf_Dispatcher::autoConfig()example

<?php
class Bootstrap extends Yaf_Bootstrap_Abstract{
    public function 
_initConfig() {
        
$config Yaf_Application::app()->getConfig();
        
Yaf_Registry::set("config"$config);
    }

    public function 
_initRoute(Yaf_Dispatcher $dispatcher) {
        
$router $dispatcher->getRouter();
        
/**
         * we can add some pre-defined routes in application.ini
         */
        
$router->addConfig(Yaf_Registry::get("config")->routes);
    }
?>
add a noteadd a note

User Contributed Notes 1 note

up
0
arthurzwl at gmail dot com
5 years ago
The regex route should like this.
You need add "/" before "list"
routes.route_name1.match="#^/list/([^/]*)/([^/]*)#"

官方地址:https://www.php.net/manual/en/yaf-router.addconfig.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3