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

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值