久艹网,亚洲一日韩欧美中文字幕2019,国产欧美日韩精品专区黑人,一区二区三区久久99

中山php|最優(yōu)網(wǎng)絡中山做網(wǎng)站 中山php建站

最優(yōu)良人

2011/08/16 at 10:31

FleaPHP頁面控件 WebControls的使用

如果不使用模板引擎,需要先注冊控件 $ui =& FLEA::initWebControls() ;其實就是返回控件的實例,該函數(shù)的代碼是

00662 function & initWebControls()
00663 {
00664 return FLEA::getSingleton(FLEA::getAppInf('webControlsClassName'));
00665 }

'webControlsClassName'默認是FLEA目錄下的webControls類,該類封裝了頁面組件的實現(xiàn),以及一些常用的頁面控件,在找不到這些自帶控件的時候就會去嘗試搜索我們自定義的以_ctl開頭的控件

/**
* 構(gòu)造一個控件的 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 '';
}

實例化控件之后,在模版(也就是 .php)中:

1 <?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)會自動去實例化控件對象

標簽:,
-