Yaf_Route_Rewrite::assemble

(Yaf >=2.3.0)

Yaf_Route_Rewrite::assemble组合url

说明

public Yaf_Route_Rewrite::assemble ( array $info [, array $query ] ) : string

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

参数

info

需要传入一个数组,数组中每个key必须和初始化rewrite route时$match参数中的带冒号的参数名一致

query

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

范例

Example #1 Yaf_Route_Rewrite::assemble()example

router = new Yaf_Router();

$route  = new Yaf_Route_Rewrite(
                "/product/:name/:id/*",
                array(
                        'controller' => "product",
                ),
                array()
);

$router->addRoute("rewrite", $route);

var_dump($router->getRoute('rewrite')->assemble(
                        array(
                                ':name' => 'foo',
                                ':id' => 'bar',
                                ':tmpkey1' => 'tmpval1'
                        ),
                        array(
                                'tkey1' => 'tval1',
                                'tkey2' => 'tval2'
                             )
                        )
);

以上例程的输出类似于:

string(57) "/product/foo/bar/tmpkey1/tmpval1/?tkey1=tval1&tkey2=tval2"

返回值

关注编程学问公众号