Moodle 3,开发一个区块
我收到以下错误:'缺少必需参数(id)'。
它发生在$ mform中,只有当我在重定向($ url)的'Else if'语句中使用数组('id'=> $ instance-> id)时。
令人惊讶的是,因为当我在带有重定向网址的按钮中使用相同的代码时,代码才能正常工作。
我尝试了几件事,但没有任何帮助。可能是什么问题?
以下是一些代码:
$id = required_param('id', PARAM_INT);
$instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);
$context = \context_block::instance($instance->id);
$mform = new newlink();
if ($mform->is_cancelled()) {
$url = new moodle_url('/my');
redirect($url);
} else if ($fromform = $mform->get_data()) {
// data from form
....
$url = new moodle_url('/blocks/name_of_block/links.php', array('id' => $instance->id)); // HERE IS THE PROBLEM
(Note: when I'm using here the block instance id number 123 directly, the redirect is working correct:
$url = new moodle_url('/blocks/name_of_block/links.php?id=123';)
redirect ($url);
} else {
//Set default data (if any)
$mform->set_data($toform);
//displays the form
$mform->display();
}
$url = new moodle_url('/blocks/name_of_block/links.php', array('id' => $instance->id))
echo $OUTPUT->single_button($url, get_string('button:links', 'block_name_of_block')); // THIS IS WORKING CORRECT
答案 0 :(得分:0)
是您提交表单而不是重定向?
在你的表格中你有:
public void print(final Node node) {
PrinterJob job = PrinterJob.createPrinterJob();
Printer printer = Printer.getDefaultPrinter().getDefaultPrinter();
PageLayout pageLayout =
printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, Printer.MarginType.EQUAL);
JobSettings jobSettings = job.getJobSettings();
jobSettings.setPageLayout(pageLayout);
boolean printed = job.printPage(node);
if (printed) {
job.endJob();
}
}
在上面的代码中你有:
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);