Let's start with this section to learn how to apply Smarty to actual examples. To illustrate this, I'll take a site that I wrote before as an example. First of all, I am not very strong in art, so the design out of the page is not very good-looking, we will deal with the see
Before you look at this article, you can look at indexbak.htm and newsbak.htm, which are the examples we generated.
First, to explain what we are going to use the database, I will first of all the database source files to everyone example:
CREATE DATABASE News;
USE News;
/****************************
*
* 表 名: tb_news_ch
* 用 途: 国内新闻表
*
****************************/
CREATE TABLE tb_news_ch
(
iNewsID interger (11) primary key auto_increment,
vcNewsTitle varchar(50) not null,
ltNewsContent longtext not null
);
/****************************
*
* 表 名: tb_news_in
* 用 途: 国际新闻表
*
****************************/
CREATE TABLE tb_news_in
(
iNewsID interger(11) primary key auto_increment,
vcNewsTitle varchar(50) not null,
ltNewsContent longtext not null
);
/****************************
*
* 表 名: tb_news_mu
* 用 途: 娱乐新闻表
*
****************************/
CREATE TABLE tb_news_mu
(
iNewsID interger(11) primary key auto_increment,
vcNewsTitle varchar(50) not null,
ltNewsContent longtext not null
);
I'll simply explain the database here.
First question:
As you can see, in fact, 3 data tables have the same field names, so why not combine them into a single datasheet? The answer is simple: efficiency, in the development of the time we may not feel what can improve the efficiency of the place, but you think, when the site runs for a period of time, its news data volume will be very large, And considering that if the future of the site will be larger after the various types of separation to form a similar china.xxx.com, international.xxx.com, music.xxx.com, separate each column out of the physical to make a separate site, At that time if the news is still put together will create a database bottleneck, so for the current site, I think it is more reasonable to separate.
Second question:
Someone may ask, you add in front of the field I, vc,lt what to use? This is named after the field type, which is also the embodiment of a good style, where the type prefix is placed before the variable, and the user can know what type of field is without looking at the field definition, as referenced by Microsoft's Hungarian nomenclature. When designing a database, I first define each type as 1-3 letters, and then add the corresponding code in front of each field to represent its type. Like above, I define individual database field types as:
Integer i
varchar VC
Longtext LT
Char C
....
When used, you can enter 5 data records in each datasheet for us to use when debugging the instance.
Second, the sample site directory structure:
PHP Code:--------------------------------------------------------------------------------
+web (site root directory)
|
|----+comm (smarty Related documents directory)
| |
| |----+plugins (smarty plugin directory)
| | |-----Config_File.class.php (smarty configuration file)
| |-----Smarty.class.php (Smarty class master file)
| | |-----Smarty_Compiler.class.php (Smarty compilation class file)
|
|----+cache (smarty cache directory, *nix guaranteed read and Write permissions)
|
|----+templates (site template file storage directory)
| |
| | |----HEADER.TPL (page header template file)
| |----INDEX.TPL (site template file)
| | |----FOOT.TPL (page footer template file)
| | |----NEWS.TPL (News page template file)
|
|
|----+templates_c (the template file is compiled and stored in the directory, *nix guaranteed read and Write permissions)
|
|----+CSS (site CSS file directory)
|
|----+image (site picture catalogue)
|
|----+media (SITE Flash animation storage directory)
|
|----indexbak.htm (Original effect Chart of home page)
|
|----newsbak,htm (News page original effect chart)
|
|----index.php (smarty Homepage program file)
|
|----news.php (SMARTY News display file)
|
|----Routines description. TXT (directory description)
|
|----database to create a file. txt (Database setup document)
For more information, please download the example and compare the structure chart.
------------------------- -------------------------------------------------------