MVC Architecture Learning Smarty Learning-sick and listless

Source: Internet
Author: User
Tags zend

The first two days are 51 small long vacations, and every vacation is thinking how to work hard, often is unrequited.

Of course, this time there is a small illness in the body, a number of excuses.

A sick on the listless not ... To exercise, ah, foot estimates are almost, swimming try it this week.

This study smarty the engine.

I. Introduction to the View engine

Help users achieve the development of view in MVC.

(a template that can be understood as a view

--Good view engine

close to HTML;

The grammar is simple and understandable;

A good caching mechanism;

Good extensibility;

More network resources

(So learn the existing view engine first)

--well-known

Smarty,phplib

Ii. introduction of Smarty

Provides separation of logic and external content (the separation of PHP programmer and art work ;

Introduction of Baidu

Then the direct official website or github download is good;

Among them, the demo is the official example, it is said to be very good;

Libs inside is the file we want to introduce, as follows:

Smarty.class.php is the instantiation to use, plugins is a plug-in, you can write and put it in use;

Introduction, configuration and example production of Smarty

1. Introduction and instantiation

First of all, or my personal environment, said before: PHP5.4 (Forget) +zend+wampserver

Create the project and put the demo and Libs in.

Then the code is written in the index.php;

Referring to the code specification for Smarty.class.php, I wrote a personal table header

1<?PHP2 /**3 * Project:mvcsmartytry4 * File:index.php5  * 6 * This file is the test file of using Smarty.7  * 8 * @copyright Andy Liang9 * @author Andy LiangTen * @package Smarty One * @version 3.1.30-dev A  */

And then it's simply introduced and instantiated.

1 namespace Mvcsmarty\index;2 /**3 * Require The main file of Smarty4  */5 require' Smarty.class.php ';6  7 /**8 * Instantiation of Smarty9  */Ten $smarty=New\smarty ();

Note that when instantiating, you can look at the specific class name of the class.php, and then the selection of require and include will not be discussed, as mentioned above;

In general, the sense of instantiation is not the last backslash, may be the zend of the problem, I check it again.

2. Configuration related

This special class, has made a lot of properties and methods, online there are many configuration tutorials, here to mention a few common things;

Especially two methods: Display and assign

1 /**2 * Configuration of Smarty3 * especially five configs & functions4  */5 $smarty->left_delimiter = "{";6 $smarty->right_delimiter = "}";7 //actually see the source code will find: and the source of the configuration is the same;8 //Then there is the templates template file storage address9 //templates_c template Compilation of generated filesTen //These two are protected or private One //This version of the Smarty in the modification of these settings is a method A //such as Settemplatedir, as if it were this - //In short, read more source - $smarty->cache_lifetime = 120; the  - /** - * The most frequently-used methods. -  */ + $smarty->assign (' ArticleTitle ', ' article title '); - $smarty->display ('./templates/test.tpl ');

Assign is an assignment, but an assignment in a template;

Display, as its name implies, is displayed;

Show you the demo!

<?PHP/** * Example application * * @package example-application*/require‘.. /smarty.class.php ';$smarty=NewSmarty;//$smarty->force_compile = true;$smarty->debugging =true;$smarty->caching =true;$smarty->cache_lifetime = 120;$smarty->assign ("Name", "Fred Irving Johnathan Bradley Peppergill",true);$smarty->assign ("FirstName",Array("John", "Mary", "James", "Henry"));$smarty->assign ("LastName",Array("Doe", "Smith", "Johnson", "case")));$smarty->assign ("Class",Array(Array("A", "B", "C", "D"),Array("E", "F", "G", "H"),Array("I", "J", "K", "L"),Array("M", "N", "O", "P")));$smarty->assign ("Contacts",Array(Array("Phone" = "1", "Fax" + "2", "Cell" = "3"),Array("Phone" = "555-4444", "Fax" + "555-3333", "Cell" and "760-1234")));$smarty->assign ("Option_values",Array("NY", "NE", "KS", "IA", "OK", "TX"));$smarty->assign ("Option_output",Array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas"));$smarty->assign ("option_selected", "NE");$smarty->display (' Index.tpl ');

3. Demo Learning

---------tomorrow more, see Bibel to the----------

MVC Architecture Learning Smarty Learning-sick and listless

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.