在当前页面上,我已经有了button
,而enrols
是我在一门课程中的,现在我想将这样的button
添加到download
,即pdf
中的课程摘要。当前按钮如下所示:
.= html_writer::div(html_writer::tag("button", get_string('enrol', 'local_customenrol'), array('class' => 'ebutton')), 'enrol');
我添加了Download in PDF
按钮,如下所示:
.= html_writer::div(html_writer::tag("button", get_string('printpdf', 'local_customenrol'), array('class' => 'printpdf')), 'printpdf');
注册按钮在local_customenrol.js
中与javascript
一起工作,页面摘要的打印在printpdf.php
中进行,我只是无法触发download
。如果可能的话,我倾向于使用php
,还是应该使用javascript
?
我发现,要打印到课程摘要文件的链接,必须执行以下操作:
$course = get_course($courseid);
$url = '';
foreach ($course->get_course_overviewfiles() as $file) {
$url = file_encode_url($CFG->wwwroot.'/pluginfile.php',
'/'.$file->get_contextid().'/'.
$file->get_component().'/'.
$file->get_filearea().
$file->get_filepath().
$file->get_filename(), !$isimage);
echo html_writer::link($url, 'Download course file', array('class' => 'btn btn-secondary span3'));
}
有了这个,你将为附加到现有课程的每个文件打印一个链接,并且不需要使用php渲染PDF。