如何将 URL 变量传递给 Silverstripe 中的表单
How to Pass URL Variables to a Form in Silverstripe
我正在开发一个自定义电子邮件表单,它应该能够处理以下 URLs:
http://www.example.com/email
默认为通用电子邮件地址。
http://www.example.com/email/Office/1
从 Office 模型,ID 1 获取电子邮件联系方式
http://www.example.com/email/Staff/96
从员工模型、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 变量到表单的最佳方式是什么?
$ID = $this->request->param('ID');
这将从您在路由中定义的 Url 参数中获取 ID,或者 $url_handlers.The 使用相同的方法获取操作参数。
我正在开发一个自定义电子邮件表单,它应该能够处理以下 URLs:
http://www.example.com/email
默认为通用电子邮件地址。
http://www.example.com/email/Office/1
从 Office 模型,ID 1 获取电子邮件联系方式
http://www.example.com/email/Staff/96
从员工模型、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 变量到表单的最佳方式是什么?
$ID = $this->request->param('ID');
这将从您在路由中定义的 Url 参数中获取 ID,或者 $url_handlers.The 使用相同的方法获取操作参数。