首页 > 解决方案 > 如何在OctoberCMS中动态获取查看页面上的ID

问题描述

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

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

我怎样才能得到这个网址的ID?

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

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

标签: octobercmsoctobercms-pluginsoctobercms-backend

解决方案


从后端我们可以得到参数,但我们需要使用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那么使用这个答案两者都可以。

十月CMS | 在控制器中,在 preview.htm 上创建编辑按钮,然后链接到具有相同 ID 的 update.htm

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


推荐阅读