Name
registerDefaultPluginHandler() 鈥 娉ㄥ唽榛樿鎻掍欢澶勭悊鍣
璇存槑
void聽registerDefaultPluginHandler(mixed聽callback);娉ㄥ唽涓涓粯璁ょ殑鎻掍欢澶勭悊鍣紝褰撶紪璇戠▼搴忔棤娉曟壘鍒版ā鏉夸腑鏍囩瀹氫箟鐨勬椂鍊欙紝灏嗚皟鐢ㄨ繖涓鐞嗗櫒杩涜鍥炶皟銆 鍙傛暟锛
-
callbackdefines the PHP callback. it can be either:A string containing the function
nameAn array of the form
array(&$object, $method)with&$objectbeing a reference to an object and$methodbeing a string containing the method-nameAn array of the form
array($class, $method)with$classbeing the class name and$methodbeing a method of the class.
褰揝marty鍦ㄧ紪璇戣繃绋嬩腑閬囧埌鏈畾涔夛紙娌℃湁娉ㄥ唽鐨勬彃浠舵垨鑰呬笉鍦ㄦ彃浠剁洰褰曚笅锛夌殑鏍囩鏃讹紝Smarty灏嗚瘯鍥捐皟鐢ㄩ粯璁ょ殑鎻掍欢澶勭悊鍣ㄦ潵澶勭悊銆 濡傛灉鏈畾涔夋爣绛炬槸鍦ㄥ惊鐜腑锛屽垯璇ュ鐞嗗櫒灏嗘湁鍙兘琚娆¤皟鐢ㄣ
Example聽14.38.聽榛樿鎻掍欢澶勭悊鍣ㄤ緥瀛
<?php
$smarty = new Smarty();
$smarty->registerDefaultPluginHandler('my_plugin_handler');
/**
* 榛樿鎻掍欢澶勭悊鍣
*
* 褰揝marty鍦ㄧ紪璇戣繃绋嬩腑閬囧埌鏈畾涔夌殑鏍囩鏃惰皟鐢
*
* @param string $name 鏈畾涔夋爣绛剧殑鍚嶇О
* @param string $type 鏍囩绫诲瀷 (姣斿锛 Smarty::PLUGIN_FUNCTION锛孲marty::PLUGIN_BLOCK锛
Smarty::PLUGIN_COMPILER锛孲marty::PLUGIN_MODIFIER锛孲marty::PLUGIN_MODIFIERCOMPILER)
* @param Smarty_Internal_Template $template 妯℃澘瀵硅薄
* @param string &$callback 杩斿洖 鍥炶皟鍑芥暟鍚
* @param string &$script 褰撳洖璋冨嚱鏁版槸澶栭儴鐨勶紝鍙繑鍥 鍑芥暟鎵鍦ㄨ剼鏈殑璺緞銆
* @param bool &$cacheable 榛樿true锛 濡傛灉鎻掍欢鏄笉鍙紦瀛樼殑璁剧疆鎴恌alse (Smarty >= 3.1.8)
* @return bool 鎴愬姛杩斿洖true
*/
function my_plugin_handler ($name, $type, $template, &$callback, &$script, &$cacheable)
{
switch ($type) {
case Smarty::PLUGIN_FUNCTION:
switch ($name) {
case 'scriptfunction':
$script = './scripts/script_function_tag.php';
$callback = 'default_script_function_tag';
return true;
case 'localfunction':
$callback = 'default_local_function_tag';
return true;
default:
return false;
}
case Smarty::PLUGIN_COMPILER:
switch ($name) {
case 'scriptcompilerfunction':
$script = './scripts/script_compiler_function_tag.php';
$callback = 'default_script_compiler_function_tag';
return true;
default:
return false;
}
case Smarty::PLUGIN_BLOCK:
switch ($name) {
case 'scriptblock':
$script = './scripts/script_block_tag.php';
$callback = 'default_script_block_tag';
return true;
default:
return false;
}
default:
return false;
}
}
?>
Note
鍥炶皟鏂规硶蹇呴』鏄潤鎬佺殑锛屽鍑芥暟鍚嶇О鎴栬呬竴涓寘鍚被鍜屾柟娉曞悕鐨勬暟缁勩
涓嶆敮鎸佸瀵硅薄鏂规硶绛夊姩鎬佺殑鍥炶皟銆
