Moodle require_login 函数

该函数是用来 检查用户是否登录到网站或者课程 ( 有些课程可能设置成不需要 登录). 如果需要 登录网站 ,但 用户 又没有 登录 ,就将页面重定位到登录页面 。反之他已经登录,但正在尝试访问课程 ,但又没有注册到该课程,那么执行该函数就会将这些用户重定向到注册函数。
输出 html header 的函数有 2 个 print_header 和 print_header_simple
输出 html body 是由 course 的特定 format 来 handle. 首先要先 include 该 course 的 format 的 php file.
require($CFG->dirroot .‘/course/format/’. $course->format .‘/ format.php’);
例如,如果 course 使用 topics format ,就会 include /course/format/topics/format.php.
该 format.php用于处理特定的 course page的输出,包括 the blocks and main content.
print_footer 函数用于输出 footer 例 print_footer(NULL, $course);
Moodle 的设置分别处于 3 个地方:
[list]
[]直接在 config.php 里 hard code 。
[
]mdl_config table 。可以通过 administrative code and interfaces 进行控制
[*]mdl_config_plugins table 。主要是存储来自各个 plugin 的设置。可以通过 plugin administration 来进行控制
[/list]所有的配制信息都存在变量 $CFG 里( plugin 的设置则会放在 plugin 变量里)。例如 $CFG->theme包含了你的网站所选用的主题
config.php 一开始会调用 unset($CFG); 来保证在 config.php and setup.php 之前清除所有的设置.
除了 config.php 之外的所有其他设置都存储在 database 的 mdl_config table and mdl_config_plugins table 里。
那么 moodle 何时把这些来自 database 的设置赋给 $CFG?
就是在 config.php 里 include 了 lib/setup.php , setup.php 调用了
$CFG = get_config();
来执行。 get_config() 函数来自 /lib/moodlelib.php library file
注意: get_config函数不会对于在调用之前已经存在的设置进行覆盖。 ( will not overwrite any $CFG setting that has already been set) 。即它不会覆盖 config.php 里的设置 . 这意味着你可以在 config.php 里 hard code 你希望的设置,在 config.php 最后一行 include 了 setup.php ,但来自 database 的设置如果与 config.php 里的设置同名,则不会覆盖它。
对 configuration 进行修改是通过 set_config 函数。该函数会以 name value plugin name (optional) 作为参数。如果不使用了第三个参数,那么 set_confg 就会把设置存储在 mdl_config table ,如果使用这个参数,则存在 mdl_config_plugins table 。