20150211--smarty2-02

Source: Internet
Author: User

three , comprehensive case--php+smarty complete data paging 1. Database Design

p_id int

P_title varchar

p_addtime int 2, design HTML interface (OK) 3, write program

fenye.php fenye.html

Effect:

Four , program

Constant

Variable

Common methods

Cache control Technology 1, constants

Smarty_dir

2. variables

$template _dir: Template path

$compile _dir: Compiling the Directory

$config _dir: Configuration file directory

$cache _dir: Cache directory

$left _delimiter: Left delimiter

$right _delimiter: Right delimiter

$caching: Cache switch, Boolean type, True and False, default false

$cache _lifetime: Cache cycle, default 3,600 seconds 1 hours

$debugging: Debug Switch, Boolean type, default = False

$php _handling:smarty3.0 is basically invalid, default integral type

Example code:

3. Common Methods

Assign: Assigning variables to template files (value passing)

Assignbyref: Assigning variables to template files (reference passing)

Append: Assigning variables to templates as arrays (value passing)

Appendbyref: Assigning variables to templates as arrays (reference passing)

Clearallassign: Clears all assignment actions

Clearassign: Clears the specified assignment action

ClearCache: Clear Cache

Configload: Load configuration file

Clearconfig: Clear configuration information

Display: Show output template file

Fetch: Load file to String

Templateexists: Determine if template file exists

Example code:

An example of the difference between 1:assign and Assignbyref

Example 2:append method

Operating effect:

Example 3:clearassign and Clearallassign

Example 4:configload loading a configuration file

Example 5:fetch method

Function: Load file to String

Technology of Static

www. baidu.com/index.php?i d=10

www.baidu.com/index.php?id=11

www. baidu.com/index.php?i d=12

www.baidu.com/1407222879.html

www.baidu.com/14072228 the . html

Effect:

Example 6:templateexists to determine if a template exists '

Example code:

Five , Cache Chapter

Compile < Cache < static 1,cache in Smarty

The default is off, if you want to use, turn on the smarty cache switch Caching 2, use the Smarty cache

Example code:

Operating effect:

3. Caching Action

1) speed up access to your website

2) Reduce the pressure on the server

3) Reduce the pressure on the database server you 4, the cache file from "what"?

A: Compile the file 5,smarty Working principle diagram

6, is Cached Method

Basic syntax

$smarty->iscached ("Tpl.tpl")

Features: Used to detect if a template has a cache

Example 1: Reading a record in a database by Smarty

Example 2: Reduce the read of a database by caching technology

7. Clear Cache

$smarty->clearcache ("Tpl.tpl")

Clears the cache for the specified page

$smarty->clearallcache ()

Clear All page caches (Clear Cache button for CMS system background)

The cache of pages can be clearly specified through ClearCache, which we typically use for single page processing

Company Profile-----------------------------------Update page

And our clearallcache is typically used to clear all caches, by using the entire system

For example ecshop the clear Cache button in the upper right corner, dedecms update cache 8, Single-page multi-cache

www. shop.com/ show.php?i d=1 Read product content with ID 1

www. shop.com/ show.php?i d=2

www. shop.com/ show.php?i d=3

The experiment shows that only the first time access, the system can read normally, each subsequent access, the system automatically turn to the first request cache page, no matter how the parameters change

How to solve?

A: Multiple caches via single page

Basic syntax:

$smarty->display ("TPL", "unique value")

Instance code:

This feature is primarily used for detailed content pages. 9. Cache Collection

Problem: If you have more than one parameter

A: You can solve these problems by caching the collection

Example code:

The above code is mainly applied to the category page or List page 10, local cache

In the project, there may be some features or modules that do not need to be cached (such as clicks, comments), How to solve it?

$smarty->assign ("var", "value", true): The current variable is not cached (PHP entry)

{$var Nocache=true}: The current variable is not cached (Template page)

{NoCache} {/nocache}: A chunk is not cached (Template page)

Example code:

Example 1:

Example 2:

Example 3: Zone cache

Six , Filters 1. What is a filter

TPL source file =〉prefilter =〉 Compile tpl file = = Postfilter = Save to disk + compiled PHP file execution =〉output Filters (=〉 If there is smarty cache, Output The content of the filters is cached) and the output of the result.

Prefilter: Front (PRE) filter (label replaced with dynamic code)

Postfilter: Post filter (occurs when the compiled file is saved to the hard disk)

Outputfilter: Triggers This procedure when a request is forwarded back to the user 2, Verify the existence of the filter

Create filters in Smarty3.0 using the following methods

$smarty->registerfilter ($type, $callback)

$type: Define the type of filter

Pre-Filter

Post Filter

Output filter

$callback: Custom Functions

Seven , integrate smarty to MVC

1) Create Tools folder in core to save third-party framework files

2) Copy Smarty to the Tools folder in core

3) referencing the Smarty portal file in the View.class.php core view class

4) Create the following statement in the Action.class.php core controller

Public Function __constructor () {

$this->view = new View ();

$this->view->settemplatedir (' template storage path ');

}

5) the $this->view->assign () and $this->view->display () methods can be used in all controllers later

20150211--smarty2-02

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.