如果不使用模板引擎,需要先注冊(cè)控件 $ui =& FLEA::initWebControls() ;其實(shí)就是返回控件的實(shí)例,該函數(shù)的代碼是
00662 function & initWebControls()
00663 {
00664 return FLEA::getSingleton(FLEA::getAppInf('webControlsClassName'));
00665 }
'webControlsClassName'默認(rèn)是FLEA目錄下的webControls類,該類封裝了頁面組件的實(shí)現(xiàn),以及一些常用的頁面控件,在找不到這些自帶控件的時(shí)候就會(huì)去嘗試搜索我們自定義的以_ctl開頭的控件
/**
* 構(gòu)造一個(gè)控件的 HTML 代碼
*
* @param string $type
* @param string $name
* @param array $attribs
* @param boolean $return
*
* @return string
*/
function control($type, $name, $attribs = null, $return = false)
{
$type = strtolower($type);
$render = '_ctl' . ucfirst($type);
$attribs = (array)$attribs;
$__ctl_out = false;
if (method_exists($this, $render)) {
$__ctl_out = $this->{$render}($name, $attribs);
} else {
$extfilename = ucfirst($type) . '.php';
if (!isset($this->_extends[$type])) {
foreach ($this->_extendsDir as $dir) {
if (file_exists($dir . DS . $extfilename)) {
require($dir . DS . $extfilename);
$this->_extends[$type] = true;
break;
}
}
}
if (isset($this->_extends[$type])) {
$__ctl_out = call_user_func_array($render,
array('name' => $name, 'attribs' => $attribs));
}
}
if ($__ctl_out === false) {
$__ctl_out = "INVALID CONTROL TYPE \"{$type}\"";
}
if ($return) { return $__ctl_out; }
echo $__ctl_out;
return '';
}
實(shí)例化控件之后,在模版(也就是 .php)中:
2 $ui->control('textbox', 'username',
3 array(
4 'class' => 'textbox',
5 'size' => 28,
6 'maxlength' => 22,
7 )
8 );
9 ?>
如果使用smarty,調(diào)用方式就是:
{ webcontrol type='textbox' value=$textbox_value }
系統(tǒng)會(huì)自動(dòng)去實(shí)例化控件對(duì)象