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

2019-04-07 19:27:46王旭

    在检查模板标签系统之前我们应该快速的看一下ActionObjects和ViewResourcesConfig类,当在使用标准的ActionDispatcher时.

ActionObjects

    ActionDispatcher使一些对象在我们所使用的模板页面中的应用程序VIEW资源可用.3种标准的ActionObjects为:FormBean,Errors,和Value(商务数据)对象.
    一下表格显示了在FormAction和Action类中如何使用FormBean,Errors和Value对象:
    Saving ActionObjects in ActionForm Classes 
 ActionErrors  $this->saveErrors($request, $actionErrors) 
 FormBeans  $this->saveFormBean($request, $this) 
 ValueObjects  $this->saveValueObject($request, $valueObject) 

    Saving ActionObjects in Action Classes 
 ActionErrors  $this->saveErrors($request, $actionErrors) 
 FormBeans  $this->saveFormBean($request, $form) 
 ValueObjects  $this->saveValueObject($request, $valueObject) 

    Retrieving ActionObjects in View Resources (Templates) 
 ActionErrors  $errors->getItemString('logon_username_reqd') 
 FormBeans  $form->username 
 ValueObjects  $data->salesNorth 

    一个ActionObject将被初始化为NULL如果对象没有在之前被创建和保存.要想得到ActionObjects的详细信息请看这里:http://www.phpmvc.net/docs/guides/guidesIdx.php?doc=action-objects

View Resources

    ActionDispatcher也能暴露ViewResourcesConfig对象到我们的模板页面中.ViewResourcesConfig对象被phpmvc-config.xml配置文件中的<view-resources>元素所配置的.如果ViewResourcesConfig对象还没有被配置,那么一个新的实例将使用默认的ViewResourcesConfig类的属性.
    下面这段代码显示了使用模板标签系统的表达式在我们的HTML页眉模板中如何访问ViewResourcesConfig属性:
    <!-- Page Header -->
    <span>
 <@ =viewConfig.getAppTitle @>
    </span>

配置Action Dispatcher

    ActionDispatcher是默认的PHP.MVC(在beta 0.4.0以上版本)Dispatcher类.这个Action Dispatcher被包含于框架将默认被使用,除非我们定义了一个类来替代Dispatcher类.在下一节中我们将看到怎样配置我们的应用程序来使用一个替代类--TagActionDispatcher类.

相关文章 大家在看