Home  >  Article  >  Backend Development  >  php—Smarty-7(24)

php—Smarty-7(24)

WBOY
WBOYOriginal
2016-08-08 09:24:48887browse

3. Method

l assign :Assign variables to templates

l assignByRef: assign variables to templates (pass by reference)

l append : Append template variables to an array

l appendByRef: Append template variables to an array (pass by reference)

l clearAllAssign

Clear all assigned variables

l clearCache

Clear cache

l configLoad Load configuration file

In smarty, there are two ways to load configuration files:

1) In the template {config_load file=’….’}

2) In the program $smarty->configLoad($file[,$section])

l clearConfig

Clear all configuration file variables

l display

Read, replace, output

l fetch

Read, replace, return

l templateExists: Determine whether the template exists

Trying to load a template that does not exist will result in an error, you should judge before displaying

The difference between assign and assignByRef:

The difference between

Display and fetch:

4. Filter

Filters are used to filter data

1. Type of filter:

1) Prefilters

2) Postfilters

3) Output Filters

According to different triggering times, the above three filters are divided into

2. Workflow

tpl source file => Prefilter => Compile tpl file => Postfilter => Save to disk => Execute the compiled php file => Output Filters (=> If there is smart cache, the contents of Output Filters will be cached ) => Result output.

3. Register filter

In Smarty, filters must be registered before they can be used

In 2.6, register filters

l Prefilters

          $smarty->register_prefilter(“func”);

l Postfilters

          $smarty->register_postfilter(“func”);

l Output Filters

          $smarty->register_outputfilter(“func”);

Register different filters to call different methods.

In 3.0, register filters

$smarty->registerFilter($type, $callback);

$type: filter type

                Value range:

                       Pre: Pre-filter

Post: Post filter

Output: Output filter

$callback: filter function

4. Code:

Pre-filter and post-filter will be executed when compiled for the first time, or will be executed again after the template is changed

The output filter is executed every time

The above introduces php-Smarty-7 (24), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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