octobercms - 如何在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>
这种方式行不通......有什么想法吗?
解决方案
从后端我们可以得到参数,但我们需要使用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
如有任何疑问,请发表评论。
推荐阅读
- mysql - 估计列大小
- python - BeautifulSoup 无法解析网站
- powershell - 如何在 SharePoint Online 中更新托管元数据文件属性
- excel - 使用 Power Query 导入格式奇特的 CSV
- angular - 从 Angular 5 升级到 Angular 6 后:当前文档没有文档类型
- powershell - PowerShell脚本使用扩展名查找文件并排除文件夹
- php - phpredis zRange 返回
- c# - 使用 ASP.Net Core 2.0 C# 在 MongoDB 中插入实时数据
- r - 在包函数中使用 data.table 失败
- ruby - Protobuf 解析文本