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.

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

报告相同问题?

悬赏问题

  • ¥15 在虚拟机中安装flash code
  • ¥15 单片机stm32f10x编写光敏电阻调节3.3伏大功率灯亮度(光强越大灯越暗,白天正常光强灯不亮,使用ADC,PWM等模块)望各位找一下错误或者提供一个可实现功能的代码
  • ¥20 verilog状态机方法流水灯
  • ¥15 pandas代码实现不了意图
  • ¥15 GD32H7 从存储器到外设SPI传输数据无法重复启用DMA
  • ¥25 LT码在高斯信道下的误码率仿真
  • ¥45 渲染完成之后将物体的材质贴图改变,自动化进行这个操作
  • ¥15 yolov5目标检测并显示目标出现的时间或视频帧
  • ¥15 电视版的优酷可以设置电影连续播放吗?
  • ¥50 复现论文;matlab代码编写