doulian7305 2016-07-18 19:48
浏览 44
已采纳

Phalcon PhP - 如何在控制器内使用命名路由

I'm having trouble finding how to get the Urls from named routes inside a Phalcon PhP controller. This is my route:

$router->add(
    '/admin/application/{formUrl:[A-Za-z0-9\-]+}/{id:[A-Za-z0-9\-]+}/detail',
    [
        'controller' => 'AdminApplication',
        'action' => 'detail' 
    ]
)->setName("application-details");

I want to get just the Url, example: domain.com/admin/application/form-test/10/detail . With the code below I can get the html to create a link, the same result of the link_to.

$url = $this->tag->linkTo(
    array(
        array(
            'for' => 'application-details',
            'formUrl' => $form->url,
            'id' => $id
        ), 
        'Show'
    )
);

The result I want is just the Url. I'm inside a controller action. I know it must be really simple, I just can't find an example. Can you help me?

Thanks for any help!

  • 写回答

1条回答 默认 最新

  • dtzh131555 2016-07-18 20:05
    关注

    You should use the URL helper. Example:

    $url = $this->url->get(
        [
            'for' => 'application-details', 
            'formUrl' => $form->url,
            'id' => $id,
        ], 
        [
            'q' => 'test1',
            'qq' => 'test2',
        ]
    );
    

    You can pass second array for query string params if needed.

    According to your route definition, the above should output something like:

    /admin/application/form-url/25/detail?q=test1&qq=test2

    More info of Generating URIs in the docs.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备