ホームページ  >  記事  >  バックエンド開発  >  Smarty では assign() 関数はどのように定義されていますか?

Smarty では assign() 関数はどのように定義されていますか?

PHP中文网
PHP中文网オリジナル
2016-06-23 13:57:501862ブラウズ

この関数のコードとその原理を投稿できる人


ディスカッション(解決策)に返信

IDEを使用して調べることができます。

smarty_internal_data.php

/**     
* assigns a Smarty variable     
*     
* @param array|string $tpl_var the template variable name(s)     
* @param mixed        
$value   
the value to assign     
* @param boolean      
$nocache if true any output of this variable will be not cached     
* @param boolean $scope the scope the variable will have  (local,parent or root)     

*/    
public function assign($tpl_var, $value = null, $nocache = false)    
{        
if (is_array($tpl_var)) {            
foreach ($tpl_var as $_key => $_val) {                
if ($_key != '') {                    
if (isset($this->tpl_vars[$_key])) {                        
$this->tpl_vars[$_key]->value = $_val;                        
$this->tpl_vars[$_key]->nocache = $nocache;                    
} 
else 
{                        
$this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache);                    
}                
}            
}        
} 
else 
{            
if ($tpl_var != '') 
{                
if (isset($this->tpl_vars[$tpl_var])) 
{                    
$this->tpl_vars[$tpl_var]->value = $value;                    
$this->tpl_vars[$tpl_var]->nocache = $nocache;                
} 
else 
{                    
$this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache);                
}            
}        
}    
}


上記は、smarty の assign() 関数がどのように定義されているかを示しています。さらに関連する内容については、PHP 中国語 Web サイト (www.php.cn) に注目してください。


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。