我想在SilverStripe(v3.4)Admin。
中创建一个完全自定义的页面它应该只显示一个表单(由UploadField和FormAction组成以提交文件),该表单提交自定义操作。
到目前为止,这是我的代码。
class ImporterAdmin extends LeftAndMain {
private static $url_segment = 'importer';
private static $url_rule = '/$Action';
private static $menu_title = 'Produkt Import';
private static $menu_icon = 'mysite/icons/pimport-icon.png';
private static $allowed_actions = array(
"run_import" => true
);
public function init() {
parent::init();
// Gather required client side resources
Requirements::javascript(CMS_DIR . '/javascript/CMSMain.EditForm.js');
}
public function index($req){
return $this->renderWith("ImporterAdmin_Content");
}
public function getResponseNegotiator() {
// Get the reponse negotiator
$negotiator = parent::getResponseNegotiator();
$controller = $this;
// Set the callback template
$negotiator->setCallback('CurrentForm', function() use(&$controller) {
return $controller->renderWith('ImporterAdmin_Content');
});
return $negotiator;
}
public function getImportForm($id = null, $fields = null) {
$fields = new FieldList(
UploadField::create("XMLFile", "XML File")
);
// Get the form actions
$actions = new FieldList(
FormAction::create('run_import', _t('CMSMain.SAVE', 'Save'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
);
// Create the form
$form = CMSForm::create($this, 'ImportForm', $fields, $actions)->setHTMLID('Form_ImportForm');
// Set the response action, mostly for returning the correst template
$form->setResponseNegotiator($this->getResponseNegotiator());
// Add required classes to the form
$form->addExtraClass('cms-content center cms-edit-form');
// Convert buttons to button tags (apprently required for jQuery styling)
$actions = $actions->dataFields();
if($actions) {
foreach($actions as $action) {
$action->setUseButtonTag(true);
}
}
return $form;
}
/**
* Save the settings
* @param array $data The form data
* @param CMSForm $form The form object
* @return SS_HTTPResponse The SilverStripe viewresponse
*/
public function run_import($data, $form) {
print_r($data, $form);
}
但它什么都没显示......
ImportForm.ss文件只包含Variable $ ImportForm