[英]Simple form for Model Admin in Silverstripe
By default, Model Admin is used to manage a model/s, and if the model is skipped, the result is an error. 默认情况下,Model Admin用于管理一个或多个模型,如果跳过该模型,则结果为错误。
/* private static $managed_models = array(
'OneModel'
); */
I want to display a simple form (Textfield for a password and an action button) first, then if the password is correct, it should go the to a the gridfield. 我想先显示一个简单的表单(密码的文本字段和一个操作按钮),然后如果密码正确,则应将其转到网格字段。
I tried to change the getCMSfields inside the model, but the field is visible only if i click on one of the records from the gridfield: 我试图更改模型中的getCMSfields,但是仅当我单击gridfield中的记录之一时,该字段才可见:
public function getCMSfields(){
$fields = FieldList::create(TabSet::create('Root', $login = Tab::create('Authorise',
TextField::create('Password')
)));
return $fields;
}
Edit: 编辑:
This secondary password it's the key to decrypt the data for that DataObject, is not a regular login, so it's an additional security method to keep safe some sensitive data. 此辅助密码是解密该DataObject的数据的密钥,不是常规登录,因此它是一种安全的方法,可以保护某些敏感数据的安全。
I figured out, for those in similar situation. 我想出了类似情况的人。 Instead of using ModelAdmin, we can use LeftAndMain.
除了使用ModelAdmin,我们还可以使用LeftAndMain。 so the code will be:
所以代码将是:
class Applications extends LeftAndMain {
static $url_segment = 'applications';
static $menu_title = 'Applications';
static $url_rule = '$Action/$ID';
public function init(){
parent::init();
}
private static $allowed_actions = array(
'login'
);
public function getEditForm($id = null, $fields = null) {
$fields = new FieldList(
TextField::create('Password', ' Password')
);
$actions = new FieldList(new FormAction('applicationPassword'));
return new Form($this, "EditForm", $fields, $actions);
}
public function applicationPassword($data, Form $form){
$pass = $data['Password'];
$form->sessionMessage('Password submited for testing : '.$pass, 'success');
return $this->redirect('login');
}
public function login(){
return 'success';
}
}
One more need would be, after validation, in the nest step to show the regular gridfield with the model records, but when i succed, i will return with an answer as well. 验证之后,还需要在嵌套步骤中显示带有模型记录的常规gridfield,但是当我成功时,我也会返回一个答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.