【问题标题】:How to Pass URL Variables to a Form in Silverstripe如何将 URL 变量传递给 Silverstripe 中的表单
【发布时间】:2016-06-12 23:21:22
【问题描述】:

我正在开发一个应该能够处理以下 URL 的自定义电子邮件表单:

http://www.example.com/email

默认为一般电子邮件地址。

http://www.example.com/email/Office/1

从 Office 模型,ID 1 获取电子邮件联系人详细信息

http://www.example.com/email/Staff/96

从 Staff 模型中获取电子邮件联系方式,ID 96

我认为我可以通过访问普通的 $Action/$ID 变量来做到这一点 - 但被路由文档完全弄糊涂了:https://docs.silverstripe.org/en/3.3/developer_guides/controllers/routing/

class EmailPage_Controller extends Page_Controller
{

  private static $allowed_actions = array(
    'Form',
    'Staff',
    'Office'
    );

  public function Form() { 

    $Action = $this->request->getVar('Action');
    $ID = $this->request->getVar('ID');  

没用。

在 Silverstripe 中访问/传递 URL 变量到表单的最佳方式是什么?

【问题讨论】:

    标签: php silverstripe


    【解决方案1】:
    $ID = $this->request->param('ID');
    

    这将从您在路由或 $url_handlers 中定义的 Url 参数中获取 id。使用相同的方法获取操作参数。

    【讨论】:

    • 这正是我需要做的。我通常使用 param() 但必须从其他代码中复制/粘贴 getVar()。
    猜你喜欢
    • 2017-01-06
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    相关资源
    最近更新 更多