Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问如何在controller中使用assemble构建url #437

Open
shyandsy opened this issue Mar 28, 2019 · 1 comment
Open

请问如何在controller中使用assemble构建url #437

shyandsy opened this issue Mar 28, 2019 · 1 comment

Comments

@shyandsy
Copy link
Contributor

shyandsy commented Mar 28, 2019

assemble可以生成url

请问如何在controller中获得Yaf_Router对象?

php官网的例子是这样子的

$router = new Yaf_Router();

$route  = new Yaf_Route_Map();
$router->addRoute("map", $route);

var_dump($router->getRoute('map')->assemble(
                        array(
                                ':c' => 'foo_bar'
                        ),
                        array(
                                'tkey1' => 'tval1',
                                'tkey2' => 'tval2'
                        )
                   )
);

$route = new Yaf_Route_Map(true, '_');
$router->addRoute("map", $route);
var_dump($router->getRoute('map')->assemble(
                        array(
                                ':a' => 'foo_bar'
                        ),
                        array(
                                'tkey1' => 'tval1',
                                'tkey2' => 'tval2'
                        )
                   )
);

在boostrap中创建路由,在controller中如何得到路由对象呢?

尝试1

  • 路由配置
routes.login.type="regex"
routes.login.match="#^/user/login#"
routes.login.route.controller=user
routes.login.route.action=login
  • assemble用法
$application = Yaf\Application::app();
$router = $application->getDispatcher()->getRouter();
$url = $router->getRoute('login');
$url = $url->assemble(
            [
                ':m' => '',
                ':c' => 'user',
                ':a' => 'login'
            ],
            []
        );
echo $url;

错误:Error Msg:Reverse property is not a valid strin

@letwang
Copy link

letwang commented May 31, 2019

使用自带的静态路由吧 性能好https://github.com/letwang/HookPHP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants