search
HomeBackend DevelopmentPHP TutorialPHP.MVC的模板标签系统(二)

The php.MVC Tag Action Dispatcher

   TagActionDispatcher是一个标准的ActionDispatcher类的实现,它支持访问基本模板标签.TagActionDispatcher类支持相同的ActionObjects集合和ViewResourcesConfig属性作为默认的ActionDispatcher.TagActionDispatcher类能被用在带有或没有带有模板标签系统上,尽管由于它的额外处理会造成小的性能下降.
   模板标签库是PHP.MVC框架结构的子系统.模板标签库联合TagActionDispatcher一起工作来支持一些简单的模板标签.
   下面的图表显示了PHP.MVC模板标签系统的总揽.左边展示的是模板标签系统的程序流程.右边是TagActionDispatcher的程序流程,还有标签模板是怎样使这些类进行交互.

模板标签系统的程序流程  

1.初始化
   当控制器传递控制到达TagActionDispatcher,一些初始化触发去设置ActionObjects和ViewResourcesConfig属性为了使用我们的模板:
   从request中重新获得$form,$errors和$data对象,如果这些对象中的任意一个已经在之前被创建(比如在Action类中),那么对象现在将在资源模板中不可见,否则对象将被设置为NULL.
   重新获得ViewResourcesConfig对象的参考,它包含了配置参数.
   设置在ViewResourcesConfig参数中指向模板源文件和编译的模板文件的路径.
2.设置标签页面
   模板源文件的扩展名(可能是".ssp")被用来和ViewResourcesConfig->tagFlagStr参数相比较来决定是否这个页面需要处理,否则页面将被处理为标准(无标签)模板文件.我们能在view-resources元素中配置标签文件扩展名,就像这样:
    ...
 tagFlagStr = ".ssp"
 tagFlagCnt = "-4"
 ...
  
   tagFlagStr指示了标签模板源文件能被预处理,比如:myPage.ssp.这个扩展名触发标签处理.属性tagFlagCnt定义了文件名结尾的字符数,包括"."(xxxYyy.ssp).据个例子,-4代表源文件名最后4个字符.默认值是.ssp和-4,因此如果我们使用一个模板文件名像myPage.ssp,我们不需要设置这些参数.
3.处理标签文件
   模板标签系统决定是否运行标签处理器,要根据ViewResourcesConfig->PRocessTags属性.如果这个属性为真,模板页(及它所包含的页)将被标签处理器类所处理,否则标签处理器不会被调用.开发者只要将它在开发中将其设置为真即可,假则不处理.但要注意的是当processTags属性设置为真,修改过的标签页才会被编译(这依赖于compileAll属性设置).我们能定义processTags属性在view-resources元素,就像这样:
    ...
 processTags = "True"
 ...
  
   注意,它的默认值是假.
4.编译模板页.
   如果TagActionDispatcher决定模板页将被处理,那么它会传递控制给模板标签系统.现在模板标签系统将决定是否只编译修改过的页,还是编译所有页.这种行为使用ViewResourcesConfig->compileAll属性来定义.我们定义compileAll属性就像这样:
    ...
 compileAll = "True"
 ...
  
   这个属性默认为假.
5.只编译修改的页.
   如果compileAll属性设置为假(默认值),那么只会编译修改过的页.据个例子,如果被请求的页面自从上次被请求以来被修改过,此页将会被编译.
6.编译所有的页.
   如果compileAll属性设置为真,模板标签系统将总是编译页面(包括包含的页面)无论此页面自从上次请求以来是否修改过.开发者使用在开发中使用这个选项能够保证所有的页面都被处理.
7.处理VIEW资源.
   在处理完模板页之后,控制权回到TagActionDispatcher.被请求的VIEW资源(模板文件)将被任何其他的正规PHP.MVC模板文件所处理.TagActionDispatcher重新获得被编译的页(包括包含的页面)并且将页面输出给用户的浏览器.如果模板标签系统没有被调用,TagActionDispatcher将被请求的页面作为正规的VIEW资源来处理.比如TagActionDispatcher能被用来代替标准的ActionDispatcher.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!