欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP.MVC的模板标签系统(五)

程序员文章站 2022-06-28 14:59:33
建立模板标签系统应用程序     建立模板标签系统应用程序只需几个步骤.    注意:以下步骤假设使用了新的s...
建立模板标签系统应用程序

    建立模板标签系统应用程序只需几个步骤.
    注意:以下步骤假设使用了新的sleek例子应用程序(这个例子可以在上找到).

修改应用程序的boot.ini文件

    应用程序的boot.ini文件包含需要得到php.mvc框架的信息.boot.ini文件通常位于应用程序的"web-inf"目录下.为了设置应用程序使用模板标签类,我们需要在boot.ini文件中定义一些属性.

tagactiondispatcher类

    tagactiondispatcher是actiondispatcher类的标准实现.为了让框架能读取tagactiondispatcher类,我们为变量$appserverrootdir设置值为'tagactiondispatcher':
// setup the application specific actiondispatcher (requestdispatcher)
 $actiondispatcher = 'tagactiondispatcher';

模板标签系统库根目录

    我们也需要设置路径指向我们的php.mvc库(需要文件系统的绝对路径):
// set php.mvc library root directory (no trailing slash).
 $appserverrootdir = 'c:\www\phpmvc-base';

可选设置

    应用程序定时器可以使用$timerrun属性来设置开或关:
// timer reporting. 1=on, 0=off
 $timerrun = 1;
    还可以指导框架总是(强制)编译应用程序phpmvc-config.xml配置类(最好用在开发阶段,因为会比较慢),我们使用:
// the application xml configuration data set:
  $appxmlcfgs = array();
  $appxmlcfgs['config'] = array('name'=>'phpmvc-config.xml', 'fc'=>true);
    或者仅在phpmvc-config.xml文件被修改的时候重新编译应用程序配置文件(在开发完成后使用此项设置,速度快),我们使用:
// the application xml configuration data set:
  $appxmlcfgs = array();
  $appxmlcfgs['config'] = array('name'=>'phpmvc-config.xml', 'fc'=>false);

设置应用程序模板目录

    当为模板标签应用程序设置模板目录时,我们需要去创建一个目录(和子目录),放置我们的应用程序模板文件.这个目录必须被命名为在view资源配置类的$tpldir属性所定义的值,默认是'./web-inf/tpl'.比如:例子应用程序有一个模板目录结构设置像这样:
- phpmvc-tags
     index.html
     main.php
     web-inf
        tpl
           pagefooter.ssp
           pageheader.ssp
           salepagebody.ssp
           sale
              pagecontent.ssp
    我们也需要去创建目录放置编译的页面.这个目录必须被命名为在view资源配置类的$tpldirc属性所定义的值.默认是'./web-inf/tpl_c'.例子应用程序有一个模板目录结构设置像这样:
phpmvc-tags
    index.html
    main.php
    web-inf
       tpl
          ...
          sale
             ...
          tpl_c
             pagefooter.sspc
             pageheader.sspc
             salepagebody.sspc
             sale
                pagecontent.sspc
    注意我们也需要在'./web-inf/tpl_c'下创建sale目录.

设置php.mvc库的路径和包含

    检查以下路径设置已经被定义在globalpaths.php和globalprepend.php文件在你的框架安装目录下的"/web-inf"目录下:
globalpaths.php
------------------------------------------------
 $appdirs[] = 'web-inf/lib/phpmvc_tags';

globalprepend.php
------------------------------------------------
 include_once 'phpmvc_tags.php';
    如果他们没有在添加到路径里,那么就定义这些变量.

安装php.mvc库

    下载最新版的php.mvc库:http://www.phpmvc.net/download/cvsidx.php?doc=cvs-snaps
    解压库文档到一个目录.修改上面所描述过的路径设置和包含设置.

运行例子应用程序

    下载例子应用程序.完整的例子代码文件和这个向导都能在这里下载:http://www.phpmvc.net/download/rel/phpmvc-tags-v1.0.zip
    解压到web服务器目录中.可能像这样:c:/www/phpmvc-tags
    修改应用程序和框架设置.
    为了测试例子程序,需要浏览器例子程序的首页:http://localhost/phpmvc-tags/index.html


附录a:viewresources配置类

    viewresourcesconfig类表现了<view-resource>元素的配置信息.
    下表列出了viewresourcesconfig类的属性,条目描述和默认值:   

name  description  default value
 $apptitle    the application title    'my web application'
 $appversion    the application version    '1.0'
 $copyright    the copyright notice    'copyright c yyyy my name. all rights reserved.'
 $contactinfo    the contact information  
 $processtags  do we run the template engine processor (boolean)   false
 $compileall  force compile pages (boolean)  false
 $tagl  the left tag identifier     '<@'
 $tagr  the right tag identifier    
 $tpldir   the view resource templates directory   './web-inf/tpl'
 $tpldirc    the compiled templates directory    './web-inf/tpl_c'
  $extc  the compiled file notation. eg: "pagecontent.ssp[c]"   'c'
 $maxfilelength    the maximum size of the template files allowed, in bytes (integer)    250000
  $tagflagstr    indicates tag template file(s) to be pre-processed. eg: "mypage.ssp"  '.ssp'
  $tagflagcnt    the number of trailing filename characters to sample (".ssp" = -4)   -4