Moodle插件开发-无法显示index.php文件中的html标题

kokeuurv  于 2023-02-28  发布在  PHP
关注(0)|答案(1)|浏览(131)

在moodle安装中,我在mysitename/local/myfolder/index.php中有下面的index.php代码
这段代码基本上是要求学生登录,然后显示他们参加的所有Moodle课程。
这很好用,但是当我试图添加简单的HTML(比如顶部的红色标题写着“我的破折号”)时,它根本不显示。我做错了什么?
代码

<?php

require_once(__DIR__ . '/../../config.php');

require_login();

$PAGE->set_context(context_system::instance());
$PAGE->set_title('Dashboard');
$PAGE->set_heading('Dashboard');
$PAGE->navbar->add('Dashboard');
echo $OUTPUT->header();

global $USER, $DB;

$courses = enrol_get_users_courses($USER->id);

echo '<!DOCTYPE html>';
echo '<html>';
echo '<head>';
echo '<title>My Dashboard</title>';
echo '<style>';
echo 'h1 { color: red; font-weight: bold; }';
echo '</style>';
echo '</head>';
echo '<body>';
echo '<h1>My Dash</h1>';

if ($courses) {
    echo '<h2>Your courses:</h2>';
    echo '<ul>';
    foreach ($courses as $course) {
        echo '<li><a href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '">' . $course->fullname . '</a></li>';

        // Get quizzes for the current course
        $quizzes = $DB->get_records_sql('SELECT q.id, q.name
                                         FROM {quiz} q
                                         INNER JOIN {course_modules} cm ON q.id = cm.instance
                                         INNER JOIN {modules} m ON m.id = cm.module
                                         WHERE cm.course = ? AND m.name = ?', [$course->id, 'quiz']);

        if ($quizzes) {
            echo '<ul>';
            foreach ($quizzes as $quiz) {
                $attempt = $DB->get_record_sql('SELECT a.*
                                                FROM {quiz_attempts} a
                                                WHERE a.quiz = ? AND a.userid = ?', [$quiz->id, $USER->id]);

                if (!$attempt) {
                    echo '<li>Quiz: <a href="' . $CFG->wwwroot . '/mod/quiz/view.php?id=' . $quiz->id . '">' . $quiz->name . '</a> (not taken)</li>';
                }
            }
            echo '</ul>';
        }

        // Get assignments for the current course
        $assignments = $DB->get_records_sql('SELECT a.id, a.name
                                              FROM {assign} a
                                              INNER JOIN {course_modules} cm ON a.id = cm.instance
                                              INNER JOIN {modules} m ON m.id = cm.module
                                              WHERE cm.course = ? AND m.name = ?', [$course->id, 'assign']);

        if ($assignments) {
            echo '<ul>';
            foreach ($assignments as $assignment) {
                $submission = $DB->get_record_sql('SELECT s.*
                                                    FROM {assign_submission} s
                                                    WHERE s.assignment = ? AND s.userid = ?', [$assignment->id, $USER->id]);

                if (!$submission) {
                    echo '<li>Assignment: <a href="' . $CFG->wwwroot . '/mod/assign/view.php?id=' . $assignment->id . '">' . $assignment->name . '</a> (not submitted)</li>';
                }
            }
            echo '</ul>';
        }
    }
    echo '</ul>';
} else {
    echo '<p>You are not enrolled in any courses</p>';
}

echo '</body>';
echo '</html>';

echo $OUTPUT->footer();
ycl3bljg

ycl3bljg1#

首先,您需要删除正在输出的所有doctype、head和body标记-所有这些标记都已由以下行输出:

echo $OUTPUT->header().

如果你想要自定义样式,那么在你的插件中创建一个styles.css文件,然后清除你的网站缓存--你添加到该文件中的任何样式都将包含在为你的整个网站服务的组合CSS文件中(只要你清除缓存或每当你更改styles.css文件时增加插件的版本号)。
查看https://docs.moodle.org/dev/CSS_Coding_Style了解更多关于在Moodle中使用CSS的信息。

相关问题