<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><th colspan="3" align="center">Smarty - the compiling PHP template engine</th></tr><tr><td width="25%" align="left" valign="bottom"><a href="advanced.features.objects.html">Prev</a></td><td width="50%" align="center" valign="bottom">Chapter 15. Advanced Features 高级特性</td><td width="25%" align="right" valign="bottom"><a href="advanced.features.prefilters.html">Next</a></td></tr></table> # [Static Classes]()[静态类] You can directly access static classes. The syntax is the same as in PHP. 可以直接访问静态类,其语法与php语法一样。 <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/> Direct access to PHP classes is not recommended. This ties the underlying application code structure directly to the presentation, and also complicates template syntax. It is recommended to register plugins which insulate templates from PHP classes/objects. Use at your own discretion.<br/> See the Best Practices section of the Smarty website.<br/> 不推荐直接访问php类。因为这样做等于将外在表现内容暗中与应用代码结构直接连结起来,而且还使模板语法复杂化。推荐使用注册插件,它能够将模板从php类/对象分离出来。不过,一切自己定夺啦~。<br/> 浏览Smarty网站中关于最佳实践的章节。</td> </tr></table> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"><a name="AEN31512" id="AEN31512"/><strong>Example 15.12. static class access syntax</strong><br/><strong>例15-12.访问静态类语法</strong><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> {assign var=foo value=myclass::BAR} &lt;--- class constant BAR<br/> {assign var=foo value=myclass::method()} &lt;--- method result<br/> {assign var=foo value=myclass::method1()-&gt;method2} &lt;--- method chaining<br/> {assign var=foo value=myclass::$bar} &lt;--- property bar of class myclass //myclass类的bar属性 <br/> {assign var=foo value=$bar::method} &lt;--- using Smarty variable bar as class name</td></tr></table></div></td></tr></table> <table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="advanced.features.objects.html">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html">Home</a></td><td width="33%" align="right" valign="top"><a href="advanced.features.prefilters.html">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Objects<br/> 对象</td><td width="34%" align="center" valign="top"><a href="smarty.for.programmers.html">Up</a></td><td width="33%" align="right" valign="top">Prefilters<br/> 预过滤器</td></tr></table>