Home Backend Development PHP Tutorial PHP.MVC的模板标签系统(二)

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

Jun 01, 2016 pm 02:27 PM

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 of this Website
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

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)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles