略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Yaf_Route_Supervar::assemble

2024-11-15

Yaf_Route_Supervar::assemble

(Yaf >=2.3.0)

Yaf_Route_Supervar::assemble组合url

说明

public Yaf_Route_Supervar::assemble(array $info, array $query = ?): string

根据指定参数和自定义参数将supervar这个route组合成一个url

参数

info

需要传入一个数组,数组中每个key可为:m、:c、:a,:m代表module,:c代表controller, :a代表action

query

用户自定义的query string,将根据此路由规则拼接在url中

范例

示例 #1 Yaf_Route_Supervar::assemble()example

<?php

$router 
= new Yaf_Router();

$route  = new Yaf_Route_Supervar('r');

$router->addRoute("supervar"$route);

var_dump($router->getRoute('supervar')->assemble(
        array(
              
':a' => 'yafaction',
              
'tkey' => 'tval',
              
':c' => 'yafcontroller',
              
':m' => 'yafmodule'
        
),
        array(
              
'tkey1' => 'tval1',
              
'tkey2' => 'tval2'
        
)
));

try {
var_dump($router->getRoute('supervar')->assemble(
        array(
              
':a' => 'yafaction',
              
'tkey' => 'tval',
              
':m' => 'yafmodule'
        
),
        array(
              
'tkey1' => 'tval1',
              
'tkey2' => 'tval2',
              
=> array(),
        )
));
} catch (
Exception $e) {
    
var_dump($e->getMessage());
}

以上例程的输出类似于:

string(%d) "?r=/yafmodule/yafcontroller/yafaction&tkey1=tval1&tkey2=tval2"
string(%d) "You need to specify the controller by ':c'"

返回值

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/yaf-route-supervar.assemble.php

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