mvc 模式在网站架构中十分常见。它允许我们建立一个三层结构的应用程式,从代码中分离出有用的层,帮助设计师和开发者协同工作以及提高我们维护和扩展既有程式的能力。
php 中有一个很著名的类库 phplib,其中有 template 模板类。能够很方便地实现代码分离在 asp 中是否也可以这样做呢?当然可以,这就是 asptemplate 的初衷。它完全实现了 phplib template 的全部功能,你可以象使用 phplib template 一样使用它,连习惯也基本不用改。:)
<%
'#######################################################################
'## name: asptemplate
'## by: bighan
'## date: nov. 28, 2003
'## site: http://asptemplate.yeah.net/
'## email: asptemplate@21cn.com
'##
'## (c) copyright 2003-2004 bighan
'#######################################################################
class asptemplate
'####
'## name of this class
'## var string
'## @access private
'## @see property: name
'####
private m_strname
'####
'## version of this class
'## var string
'## @access private
'## @see property: version
'####
private m_strversion
'####
'## determines how much debugging output template will produce.
'## this is a bitwise mask of available debug levels:
'## 0 = no debugging
'## 1 = debug variable assignments
'## 2 = debug calls to get variable
'## 4 = debug internals (outputs all function calls with parameters).
'##
'## @var int
'## @access private
'## @see property: debug
'####
private m_intdebug
'####
'## the base directory from which template files are loaded.
'##
'## @var string
'## @access private
'## @see property: root, dir; method: setroot, set_root
'####
private m_strroot
'####
'## determines how to output variable tags with no assigned value in templates.
'##
'## @var string
'## @access private
'## @see property unknown; method: setunknowns, set_unknowns
'####
private m_strunknowns
'####
'## determines how template handles error conditions.
'## "yes" = the error is reported, then execution is halted
'## "report" = the error is reported, then execution continues by returning "false"
'## "no" = errors are silently ignored, and execution resumes reporting "false"
'##
'## @var string
'## @access private
'## @see property ishalt; method: halt
'####
private m_strhalterror
'####
'## the last error message is retained in this variable.
'##
'## @var string
'## @access private
'## @see property lasterror
'##
private m_strlasterror
'####
'## opening delimiter (usually "{")
'##
'## @var string
'## @access private
'## @see property begintag
'####
private m_strbegintag
'####
'## closing delimiter (usually "}")
'##
'## @var string
'## @access private
'## @see private endtag
'####
private m_strendtag
'####
'## a hash of strings forming a translation table which translates variable names
'## into names of files containing the variable content.
'## m_ofile.item(varname) = "filename";
'##
'## @var object