<? PHP
Require 'smarty. Inc. php ';
Global $ _ smarty; // access the variable of the introduced File
// Allocate Variables
# Common variables
# This function has a third parameter, which sets whether to enable the buffer. If this parameter is set to true,
# VARIABLES will not be buffered
$ _ Smarty-> assign ('title', 'tiger started learning smarty '); // assign a value to the front-end basic variable
// $ _ Smarty-> assignbyref (): Same as above, only assigned values according to reference
# Array
$ Arr1 = array ('handler', 'maaojie '); // Index Array
$ Arr2 = array ('name' => 'huge', 'sex' => 'male'); // associate an array
$ Arr3 = array ('World' => array ('China' => 'hebei '); // two-dimensional array
$ _ Smarty-> assign ('arr1', $ arr1 );
$ _ Smarty-> assign ('arr2 ', $ arr2 );
$ _ Smarty-> assign ('arr3 ', $ arr3 );
$ _ Smarty-> assign ('str', 'Hello X3 aaa'); // used for variable modifier Testing
$ _ Smarty-> assign ('str1', 'I love ');
$ Str2 = "war dims hope for peace. Child's death ruins
Couple's holiday. Man is fatally slain. Death Causes loneliness, feeling of isolation .";
$ _ Smarty-> assign ('str2', $ str2 );
$ _ Smarty-> assign ('myname', 'huge ');
$ _ Smarty-> assign ('len', 5 );
$ Arr4 = array (1001 => 'hello', 1002 => 'World', 1003 => 'thank ');
$ _ Smarty-> assign ('arr4 ', $ arr4 );
$ Arr5 = range (1, 9 );
$ _ Smarty-> assign ('tr', array ('bgcolor = "# eeeeee" ', 'bgcolor = "# dddddddd "'));
# Clear_all_cache (); // clear all the buffers.
# $ _ Smarty-> clearallcache ();
# Clear_cache (); // clear the specified buffer
$ _ Smarty-> addconfigdir ('./config_1'); # Add a file directory
// $ _ Smarty-> setconfigdir ('./config_2'); // the configuration file has only one directory.
/*
Similar:
Addtemplatedir ('filename'): Add a template file directory.
Addpluginsdir (filename): Add plug-in Directory
Getcachedir (): Get the buffer directory
Setcachedir (filename): sets the buffer directory.
Getcompiledir (): Get the compilation directory
Setcompiledir (filename): sets the compilation directory.
Getconfigdir (): Get the configuration file directory
Setconfigdir (filename): sets the configuration file directory.
Getpluginsdir (): Get the plug-in Directory
Setpluginsdir (filename): sets the plug-in Directory
Settemplatedir (filename): sets the template directory.
*/
// The above function settings directory can be passed into the associated array or function for use, eg
/*
$ _ Smarty-> setconfigdir (Array (
'One' => 'config1 ',
'Two' => 'config2 ',
'Three '=> 'config3'
));
*/
# Method combination
/*
$ _ Smarty-> setconfigdir ('config1', 'one ')
-> Setcompiledir ('config2', 'two ');
*/
// $ Arr6 =$ _ smarty-> getconfigdir (); // get the file directory
// Print_r ($ arr6 );
// Append: Add a value to the array
$ _ Smarty-> append ('arr5 ', '1'); // an error occurs when it is placed in html_table like assign.
$ _ Smarty-> append ('arr5 ', '2 ');
$ _ Smarty-> append ('arr5 ', $ arr5 );
// Appendbyref (): Same as append, only adding values to the array by referencing
// $ _ Smarty-> clearallassign (); // clear all allocation Variables
// Similar:
// Clearallcache: Clear all Buffers
// Clearassign ('name'): clears the specified value. If multiple values are cleared, you can use the associated array.
// Clearassign ('demo1. tpl'): clears the buffer of the specified template. You can also set the specified buffer.
// The buffer of the punch ID, compilation ID, and lifecycle
// Clearcompiledtemplate: clears the compilation template file. The parameters are the same as above.
// Clearcofig (): clears the configuration. If the variable name is specified, the specified variable is cleared.
// $ _ Smarty-> compileallconfig ('. conf'); // compile all the configuration files with the following parameters:
// File suffix; Whether to forcibly compile all files; false indicates to compile only modified files;
// Timelimit: sets the time limit for template compilation. The default value is unlimited. The maximum parameter is
// The number of errors is the maximum number of errors set. If this number is exceeded, compilation stops.
/*
Similar functions include
Compilealltemplates: compile all templates with the same parameters as above
*/
// $ _ Smarty-> configload ('filename'): load the configuration file. The function is the same as that of the {cofigload} tag.
/*
$ Data =$ _ smarty-> createdata (); // create a data object to save the assignment
// Assign values to Data Objects
$ Data-> assign ('foo', 'bar ');
// Create a template object and load the data object into it as a value assignment
$ TPL =$ _ smarty-> createtemplate ('demo1. tpl', $ data );
$ TPL-> display ();
*/
/*
$ _ Smarty-> disablesecurity (); // disable the security mechanism
$ _ Smarty-> enablesecurity (); // enable the Security Mechanism
*/
// $ _ Smarty-> fetch ('template'); // capture and display the template content
// $ _ Smarty-> getconfigvars (varname): gets the preconfigured variables. If no parameter is set, it gets all the variables.
// $ _ Smarty-> getregisteredobject (objname): Get the registered object
/*
$ TPL = $ _ smarty-> createtemplate ('demo1. tpl ');
$ Tags =$ _ smarty-> gettags ($ TPL); // obtain all tags in the template
Print_r ($ tags );
*/
// $ _ Smarty-> gettemplatevars (); // get template variables. If no name is set, all variables are obtained.
/*
If ($ _ smarty-> iscached ('demo1. tpl') {// determines whether the specified template enables buffering.
Echo 'buffered ';
} Else {
Echo 'unbuffered ';
}
*/
// $ _ Smarty-> loadfilter ('pre', 'trim'); // load the filter
// $ _ Smarty-> muteexpectederrors (): Ignore script warning information
// $ _ Smarty-> unmuteexpectederrors (): removes the custom error processor.
// Register the buffer Resource
// $ _ Smarty-> registercacheresource ('name', 'resourcehandler ');
// $ _ Smarty-> registercacheresource ('name'): deregister the buffer Resource
Class myclass
{
Public static $ property = 'this is a class property ';
Function _ construct (){
}
}
$ _ Smarty-> registerclass ('myclass', 'myclass'); // registration class
// $ _ Smarty-> registerdefadefapluginhandler (): registers the default plug-in processor.
// $ _ Smarty-> registerfilter (): registers a filter.
// Unregisterfilter: deregister the filter.
// Registerresource (): registers a resource.
// Registerobject (): registration object
// Unregisterobject (): deregister object
// Registerplugins (): registers the plug-in.
// Unregisterplugin: deregister the plug-in
# Registering a function
Function my_fn ($ ARR ){
Return 'parameter value: '. $ arr ['param'];
}
$ _ Smarty-> registerplugin ('function', 'My _ player', 'My _ FN ');
Function my_bk ($ Param, $ content) {// register a Block Function
$ Res = "<span style = 'background-color :";
$ Res. = "{$ Param ['background-color']}"; // note. Parameters should be enclosed in braces
$ Res. = "'> ";
$ Res. = $ content;
$ Res. = '</span> ';
Return $ res;
}
$ _ Smarty-> registerplugin ('block', 'mybk ', 'My _ BK ');
$ _ Smarty-> setcachelifetime (3600 );
// $ Abc = new memchache ();
$ _ Smarty-> display ('demo1. tpl ');
?>
This article is from the blog of "Tiger brother", please be sure to keep this source http://7613577.blog.51cto.com/7603577/1537136