【问题标题】:How to dynamically get on url the id on view page in OctoberCMS如何在OctoberCMS中动态获取查看页面上的ID
【发布时间】:2019-10-29 17:15:24
【问题描述】:

我在控制器视图页面上有这个按钮的代码:

<button
<a href="<?= Backend::url('vimagem/pacientes/pacientes/pdf/1') ?>" 
class="btn btn-primary oc-icon-sign-out">export</a>
</button>

我怎样才能得到这个 url 的 id ?

<button
<a href="<?= Backend::url('vimagem/pacientes/pacientes/pdf/:id') ?>" 
class="btn btn-primary oc-icon-sign-out">export</a>
</button>

这种方法行不通...有什么想法吗?

【问题讨论】:

    标签: octobercms octobercms-plugins octobercms-backend


    【解决方案1】:

    我们可以从后端获取参数,但我们需要使用index。只需使用下面的代码来获取 id。

    $this->params[0] - 将为您获取第一个参数值。

    <a href="<?= Backend::url('vimagem/pacientes/pacientes/pdf/' . $this->params[0]) ?>"
    

    这里的索引0 表示我们要使用第一个参数。 index count starts after [param]action name and its based on 0-index。所以第一项的索引为 0。

    如果您的后端控制器使用的是Form-Controller behavior,那么使用这个答案都可以。

    October CMS | In the controller, create edit button on preview.htm which then links to update.htm with the same ID

    如有任何疑问,请发表评论。

    【讨论】:

    • 你好 Hardik Satasiya,我会测试它,我会留下评论。谢谢!
    • 你好@HardikSatasiya,很抱歉这么晚才说你-谢谢-你的帮助,它奏效了! :) 保持安全!
    猜你喜欢
    • 2022-01-13
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 2012-03-29
    • 2020-02-27
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    相关资源
    最近更新 更多