Using template engine smarty to develop PHP programs _php tutorial

Source: Internet
Author: User
   First, MVC needs templates
MVC was the first design pattern that was summed up in the development of the Smalltalk language, and MVC represented "model", "View" and "control", respectively, in order to make different development roles perform in large and medium-sized projects. In the development of network application, it can be used to express the relationship between the concepts.
    
The diagram shows a simple Web application in which the user sees the information on the database server, but before it is processed by the application server. Developers are responsible for building data structures, the logic of processing data, and methods of representing data. "
  
96 CGI (now not many people in use) when China began to popular, the early web programmers from the HTML began to self-learning, in Perl print line of HTML is not a difficult task, but as the network step by step, the page size from the original two, 30 K has soared 10 times times. Writing CGI (which is now used by a few people) has created an urgent requirement: to separate Perl from the HTML source. Thus, social progress is embodied in the Division of labor within the development group. Because artists and programmers are not very familiar with the work of each other, in the process of cooperation need to use a contractual "language" to communicate.
  
This language is not our mother tongue or English, the term is called "template", logic and expression rely on it to contact. It is a form of expression that combines HTML and scripting language features. In this way, the presentation layer can display data that has been processed by the logical layer in the format that the user wants. If you have the development experience of MFC under the Windows platform, then you will be familiar with the Document/document Template/view package, which is a typical example of MVC. For Web applications, the ejb/servlets/jsp (the first choice for Sun enterprise applications) in Java EE is the most powerful and, of course, a simple and graceful structs. Another well-known implementation is com/dcom+asp, which is the most used in our country.
  
By comparing several MVC implementations in Web applications, you can get a concept about templates: A set of HTML-inserted scripts or inserted script HTML to represent the changed data through this inserted content. Here is an example of a template file that is processed and displayed in the browser "Hello, world!"
  
  
   
      <title>$greetings</title>
   
   
$greetings
   
  
This is omitted for the moment, and is discussed in detail later.
  
   Second, why Choose Smarty?
For PHP (now the mainstream development language), there are many template engines to choose from, such as the earliest PHP (as the current mainstream development language) LIB template and the Rising Star fast template, after several upgrades, has been quite mature and stable. If you are satisfied with the template engine currently in hand, then ... Please also look down, I believe you as a free software enthusiast or the pursuit of efficiency and elegant developers, the following smarty how much will be a bit of meaning.
  
In addition to the impact of personal preferences, I have been inclined to use the official standards of implementation, such as the Apache (Unix platform most popular Web server platform) XML (standardization is getting closer) engine axis. The advantage is that you get the best possible compatibility (such as early MFC's compatibility with WIN3X is better than other application frameworks, and of course the various versions are now perfect). I have been using the integrated Template eXtension in Pear before Smarty was released. This engine is almost compatible with PHP (which is now the mainstream development language) LIB template, Fast template, from the syntax of the template to the processing of the template expatiating: Read the template into memory and then call the parse () function to replace the preset tag with the data.
  
Let's see how smarty is doing. After receiving the request, first determine whether the URL is requested for the first time, if so, the template file required for the URL "compiled" into PHP (as the current mainstream development language) script, and then redirect; if not, the URL template has been "compiled", The check does not need to recompile can be redirect immediately, the recompilation condition can be set to a fixed time limit, the default is the template file is modified.
  
What, does it look familiar? Remember--this is not the principle of JSP (the first choice for Sun Enterprise applications)! It is true that this "compilation" is used in the explanatory scripting engine of PHP (which is now the mainstream development language), but think about it that Java is not being interpreted by the JVM? This is called "No can not do, only unexpected."
  
Now that we have talked about Java, I would like to make a few comments about the future of PHP, which is now the mainstream development language. PHP (now the mainstream development language) announced the release of PHP at the end of 2003 (as the current mainstream development language) version 5.0. This version has many new features: exception handling, namespaces, more object-oriented, and more. It can be said that more and more toward Java, Smarty is also one of the new features, so that PHP (as the current mainstream development language) more suitable for large and medium-sized project development. But it seems that the reason I chose it--smart and easy to use--is getting farther away. But in terms of the lifetime of a software, PHP (which is now the mainstream development language) is in the growth period, the developer gives it more functions, in order to be competent for business applications is more advantages than harm. As a loyal user of PHP (now the mainstream development language), certainly do not want PHP (as the current mainstream development language) is always accused of "insufficient capacity"?

http://www.bkjia.com/PHPjc/509135.html www.bkjia.com true http://www.bkjia.com/PHPjc/509135.html techarticle First , MVC needs template MVC was originally a design pattern summed up in the development process of Smalltalk language, and MVC represented "model", "View" and "control", respectively, to make different development ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.