moodle架构分析---表现层的设计(一)

Moodle在表现层的实现有多种机制,分别针对页面、表单、导航条、页面头部、页面底部等。

 

  1、针对页面的实现,直接编辑HTML页面,然后在业务逻辑处理完毕之后,include编辑好的html页面即可。这种机制的实现可以看login/index.php和 login/index_form.php页面。

 

 

  2、针对表单的实现,一般是创建一个父类为moodleform的类,如

 

class test_form extends moodleform {

  //定义表单元素

  function definition() {

  //获得表单引用

  $mform =& $this->_form;

  //添加header对象

  $mform->addElement('header', '', get_string('createuserandpass'), '');

  //添加text对象,

  $mform->addElement('text', 'username', get_string('username'), 'maxlength="100" size="12"');

  $mform->setType('username', PARAM_NOTAGS);

  $mform->addRule('username', get_string('missingusername'), 'required', null, 'server');

  }

  //定义过滤

  function definition_after_data(){}

  //定义验证逻辑

  function validation($data, $files) {}

  }

 

 

  然后,业务逻辑层中声明test_form对象,即

 

$test = new test _form();

 

 

  最后调用test_form对象的display方法,即可把表单对象显示出来。

 

$test ->display();

 

 

  表单元素的类型和规则如下:

 

$GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] =

  array(

  'group'         =>array('HTML/QuickForm/group.php','HTML_QuickForm_group'),

  'hidden'        =>array('HTML/QuickForm/hidden.php','HTML_QuickForm_hidden'),

  'reset'         =>array('HTML/QuickForm/reset.php','HTML_QuickForm_reset'),

  'checkbox'      =>array('HTML/QuickForm/checkbox.php','HTML_QuickForm_checkbox'),

  'file'          =>array('HTML/QuickForm/file.php','HTML_QuickForm_file'),

  'image'         =>array('HTML/QuickForm/image.php','HTML_QuickForm_image'),

  'password'      =>array('HTML/QuickForm/password.php','HTML_QuickForm_password'),

  'radio'         =>array('HTML/QuickForm/radio.php','HTML_QuickForm_radio'),

  'button'        =>array('HTML/QuickForm/button.php','HTML_QuickForm_button'),

  'submit'        =>array('HTML/QuickForm/submit.php','HTML_QuickForm_submit'),

  'select'       =>array('HTML/QuickForm/select.php','HTML_QuickForm_select'),

  'hiddenselect' =>array('HTML/QuickForm/hiddenselect.php','HTML_QuickForm_hiddenselect'),

  'text'          =>array('HTML/QuickForm/text.php','HTML_QuickForm_text'),

  'textarea'      =>array('HTML/QuickForm/textarea.php','HTML_QuickForm_textarea'),

  'link'          =>array('HTML/QuickForm/link.php','HTML_QuickForm_link'),

  'advcheckbox'   =>array('HTML/QuickForm/advcheckbox.php','HTML_QuickForm_advcheckbox'),

  'date'          =>array('HTML/QuickForm/date.php','HTML_QuickForm_date'),

  'static'        =>array('HTML/QuickForm/static.php','HTML_QuickForm_static'),

  'header'        =>array('HTML/QuickForm/header.php', 'HTML_QuickForm_header'),

  'html'          =>array('HTML/QuickForm/html.php', 'HTML_QuickForm_html'),

  'hierselect'    =>array('HTML/QuickForm/hierselect.php', 'HTML_QuickForm_hierselect'),

  'autocomplete' =>array('HTML/QuickForm/autocomplete.php', 'HTML_QuickForm_autocomplete'),

  'xbutton'       =>array('HTML/QuickForm/xbutton.php','HTML_QuickForm_xbutton')

  );

  $GLOBALS['_HTML_QuickForm_registered_rules'] = array(

  'required'      => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'),

  'maxlength'     => array('html_quickform_rule_range',    'HTML/QuickForm/Rule/Range.php'),

  'minlength'     => array('html_quickform_rule_range',    'HTML/QuickForm/Rule/Range.php'),

  'rangelength'   => array('html_quickform_rule_range',    'HTML/QuickForm/Rule/Range.php'),

  'email'         => array('html_quickform_rule_email',    'HTML/QuickForm/Rule/Email.php'),

  'regex'         => array('html_quickform_rule_regex',    'HTML/QuickForm/Rule/Regex.php'),

  'lettersonly'   => array('html_quickform_rule_regex',    'HTML/QuickForm/Rule/Regex.php'),

  'alphanumeric' => array('html_quickform_rule_regex',    'HTML/QuickForm/Rule/Regex.php'),

  'numeric'       => array('html_quickform_rule_regex',    'HTML/QuickForm/Rule/Regex.php'),

  'nopunctuation' => array('html_quickform_rule_regex',    'HTML/QuickForm/Rule/Regex.php'),

  'nonzero'       => array('html_quickform_rule_regex',    'HTML/QuickForm/Rule/Regex.php'),

  'callback'      => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'),

  'compare'       => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php')

  );

 

 

  具体可以查看lib/pear/HTML/QuickForm.php,和各个表单元素和规则的实现文件。

 

来源:http://www.goodu.info/gc/node/354

 

 

 

你可能感兴趣的:(OO)