smarty 2.0版本引入了被广泛应用于自定义Smarty功能的插件机制,它包括如下类型:
    functions 函数插件
    modifiers 修饰插件
    block functions 区块函数插件
    compiler functions 编译函数插件
    prefilters 预滤器插件
    postfilters 补滤器插件
    outputfilters 输出过滤插件
    resources 资源插件
    inserts 嵌入插件

为了与旧有方式保持向后兼容,除资源插件外,保留了通过register_* API方式装载函数的处理方法。如果你不是使用API方式而是使用直接修改类变量 $custom_funcs, $custom_mods 等的方法,那么你就需要修改你的程序了。或者使用API的方法,或者将你的自定义功能转换成插件.

插件文件和函数必须遵循特定的命名约定以便Smarty识别.

插件文件必须命名如下:

type . name .php

其中type是如下插件中的一种:

  • function
  • modifier
  • block
  • compiler
  • prefilter
  • postfilter
  • outputfilter
  • resource
  • insert

name为仅包含字母、数字和下划线的合法标志符

编写插件

Smarty可自动从文件系统装载插件,或者运行时通过register_* API函数装载。可以通过unregister_* API函数卸载已经装载的插件,只在运行时装载的插件的函数名称不需要遵守命名约定。

如果某个插件依赖其它插件内的某些功能(例如某些插件功能捆绑于Smarty内),那么可以通过如下方法装载必须的插件:

require_once $smarty->_get_plugin_filepath('function', 'html_options');

4 Comments

  1. There are certainly numerous particulars like that to take into consideration. That is a great point to deliver up. I supply the ideas above as basic inspiration however clearly there are questions like the one you convey up where crucial factor will be working in honest good faith. I don?t know if finest practices have emerged round things like that, however I’m sure that your job is clearly recognized as a good game. Each boys and girls really feel the affect of just a moment’s pleasure, for the rest of their lives.

  2. Valuable information and excellent design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!! Thumbs up! I just hope to have understood this the way it was meant. My best regards, Tamiko.

发表评论

电子邮件地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


*