因此,我希望能够拥有一个仅对站点管理员可用的页面,该页面列出了提交表单的摘要和指向它们的链接。因此,一旦您单击摘要,它会将您带到一个相同的表单,让您可以编辑/更新表单。除了更新部分,我一切正常,但我被卡住了。
SubmitApplication 工作正常:
class SubmitApplicationPageController extends PageController{
protected function init()
{
parent::init();
}
private static $allowed_actions = [
'ApplicationForm'
];
public function ApplicationForm()
{
$fields = new FieldList(
TextField::create('First_Name')->setTitle('First Name'),
TextField::create('Last_Name')->setTitle('Last Name')
);
$actions = new FieldList(
FormAction::create('doSubmitApplication')->setTitle('Submit')
);
$validator = new RequiredFields([
'First Name',
'Last Name',
]);
return new Form($this, 'ApplicationForm', $fields, $actions, $validator);
}
public function doSubmitApplication($data, Form $form)
{
$submission = new Application();
$form->saveInto($submission);
$submission->write();
$form->sessionMessage('Thank you for your submission we will get back to you as soon as possible', 'success');
return $this->redirectBack();
}
}
在页面中列出仅对管理员可用的应用程序:
<ul>
<% loop $Applications %>
<li>$First_Name $Last_Name <a href="view-application/?id=$ID">View Application</a></li>
<% end_loop %>
</ul>
查看更新申请表:
private static $allowed_actions = [
'GetApplicationForm'
];
public function GetApplicationForm(){
$var = $this->getRequest()->getVar('id');
if($var){
$fields = new FieldList(
TextField::create('First_Name')->setTitle('First Name'),
TextField::create('Last_Name')->setTitle('Last Name')
);
$actions = new FieldList(
FormAction::create('doUpdateApplication')->setTitle('Update')
);
$validator = new RequiredFields([
'First Name',
'Last Name'
]);
$form = Form::create($this, 'GetApplicationForm', $fields, $actions, $validator)->loadDataFrom(Application::get()->filter(['ID' => $var])[0]);
return $form;
}
return 'This page should only be reached through the application management links. If you are here even though you did that, please contact your system admin.';
}
public function doUpdateApplication($data, Form $form)
{
//I can't figure this part out and clicking reruns the GetApplicationForm method without the get variable and doesn't run this method
}