mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
update docs
This commit is contained in:
24
BUGS
24
BUGS
@@ -1,11 +1,17 @@
|
|||||||
There are no known bugs with Smarty, although there are some bugs in PHP that
|
There are some bugs in older versions of PHP that cause problems with Smarty.
|
||||||
cause problems with Smarty. preg_replace() had a parameter added in 4.0.2 that
|
preg_replace() had a parameter added in 4.0.2 that is needed for Smarty.
|
||||||
is needed for Smarty. preg_grep() previous to 4.0.4 has a bug which Smarty has
|
preg_grep() previous to 4.0.4 has a bug which Smarty has a built-in workaround
|
||||||
a built-in workaround for. PHP 4.0.4 has a bug with user callbacks which would
|
for. PHP 4.0.4 has a bug with user callbacks which would cause this syntax in
|
||||||
cause this syntax in Smarty to crash PHP: {$varname|@modname} Use PHP 4.0.4pl1
|
Smarty to crash PHP: {$varname|@modname} Use PHP 4.0.4pl1 to fix this, or avoid
|
||||||
to fix this, or avoid using the "@" with modifiers. if you are passing variables
|
using the "@" with modifiers. if you are passing variables to {include}
|
||||||
to {include} statements, you will need PHP 4.0.4 or later, which requires the
|
statements, you will need PHP 4.0.4 or later, which requires the use of
|
||||||
use of get_defined_vars() function. Some versions of Windows 2k have a problem
|
get_defined_vars() function. Some versions of Windows 2k have a problem with
|
||||||
with flock(). Comment out the flock() command in _write_file to get around this.
|
flock(). Comment out the flock() command in _write_file to get around this.
|
||||||
|
|
||||||
To be absolutely safe, use 4.0.4pl or later with Smarty.
|
To be absolutely safe, use 4.0.4pl or later with Smarty.
|
||||||
|
|
||||||
|
Smarty versions previous to 2.0 require the PEAR libraries. Be sure to include
|
||||||
|
the path to the PEAR libraries in your php include_path. Config_file.class.php
|
||||||
|
uses the PEAR library for its error handling routines. PEAR comes with the PHP
|
||||||
|
distribution. Unix users check /usr/local/lib/php, windows users check
|
||||||
|
C:/php/pear.
|
||||||
|
41
FAQ
41
FAQ
@@ -72,18 +72,19 @@ A: Smarty reads the template files and creates PHP scripts from them. Once
|
|||||||
know of their existance. (NOTE: you can turn off this compile checking step
|
know of their existance. (NOTE: you can turn off this compile checking step
|
||||||
in Smarty for increased performance.)
|
in Smarty for increased performance.)
|
||||||
|
|
||||||
Q: Why can't I just use APC <http://apc.communityconnect.com/> (or Zend Cache)?
|
Q: Why can't I just use PHPA (http://php-accelerator.co.uk) or Zend Cache?
|
||||||
A: You certainly can. Smarty's cache and these cache solutions have nothing in
|
A: You certainly can, and we highly recommend it! What PHPA does is caches
|
||||||
common. What APC does is caches compiled bytecode of your PHP scripts in
|
compiled bytecode of your PHP scripts in shared memory or in a file. This
|
||||||
shared memory or in a file. This speeds up server response and saves the
|
speeds up server response and saves the compilation step. Smarty creates PHP
|
||||||
compilation step. Smarty creates PHP scripts (which APC will cache nicely)
|
scripts, which PHPA will cache nicely. Now, Smarty's built-in cache is
|
||||||
and also has it's own internal caching mechanism for the output of the
|
something completely different. It caches the _output_ of the template
|
||||||
template contents. For example, if you have a template that requires several
|
contents. For example, if you have a template that requires several database
|
||||||
database queries, Smarty can cache this output, saving the need to call the
|
queries, Smarty can cache this output, saving the need to call the database
|
||||||
database every time. APC cannot help you here. Smarty and APC (or Zend
|
every time. Smarty and PHPA (or Zend Cache) complement each other nicely. If
|
||||||
Cache) actually complement each other nicely. If performance is of the
|
performance is of the utmost importance, we would recommend using one of
|
||||||
utmost importance, we would recommend using one of these with any PHP
|
these with any PHP application, using Smarty or not. As you can see in the
|
||||||
application, using Smarty or not.
|
benchmarks, Smartys performance _really_ excels in combination with a PHP
|
||||||
|
accelerator.
|
||||||
|
|
||||||
Q: Why does Smarty have a built in cache? Wouldn't it be better to handle this
|
Q: Why does Smarty have a built in cache? Wouldn't it be better to handle this
|
||||||
in a separate class?
|
in a separate class?
|
||||||
@@ -96,16 +97,12 @@ A: Smarty's caching functionality is tightly integrated with the template
|
|||||||
depending on URL, cookies, etc.
|
depending on URL, cookies, etc.
|
||||||
|
|
||||||
Q: Is Smarty faster than <insert other PHP template engine>?
|
Q: Is Smarty faster than <insert other PHP template engine>?
|
||||||
A: It could be. One of the strengths of Smarty is that it does not need to
|
A: See the benchmark page for some performance comparisons. Smarty's approach
|
||||||
parse the template files on every hit to the server. Version 1.3.1 has
|
to templates is a bit different from some languages: it compiles templates
|
||||||
many noticable performance tune-ups, so your best bet is to try some
|
into PHP scripts instead of parsing them on each invocation. This usually
|
||||||
benchmarks and compare for yourself.
|
results in great performance gains, especially with complex templates.
|
||||||
|
Coupled with the built-in caching of Smarty templates, the performance is
|
||||||
The above comparison assumes that you are not using Smarty's built-in
|
outstanding.
|
||||||
ability to cache templates. If you are, that makes this comparison pretty
|
|
||||||
unfair since Smarty will basically be displaying static content instead of
|
|
||||||
generating templates, which will really speed things up especially for
|
|
||||||
complicated tests.
|
|
||||||
|
|
||||||
Q: How can I be sure to get the best performance from Smarty?
|
Q: How can I be sure to get the best performance from Smarty?
|
||||||
A: Be sure you set $compile_check=false once your templates are initially
|
A: Be sure you set $compile_check=false once your templates are initially
|
||||||
|
26
INSTALL
26
INSTALL
@@ -1,22 +1,24 @@
|
|||||||
REQUIREMENTS:
|
REQUIREMENTS:
|
||||||
|
|
||||||
Smarty requires PHP 4.0.4pl1 or later to fix all known problems Smarty has with
|
Smarty requires PHP 4.0.4pl1 or later to fix all known problems Smarty has with
|
||||||
PHP. Smarty was developed and tested with 4.0.4pl1. See the BUGS file for more
|
PHP. Smarty was developed and tested with PHP versions >= 4.0.4pl1. See the
|
||||||
info.
|
BUGS file for more info.
|
||||||
|
|
||||||
INSTALLATION:
|
INSTALLATION:
|
||||||
|
|
||||||
* copy the Smarty.class.php, Smarty.addons.php, Smarty_Compile.class.php and
|
* copy the Smarty.class.php, Smarty.addons.php, Smarty_Compile.class.php
|
||||||
Config_File.class.php scripts to a directory that is in your PHP include_path,
|
Config_File.class.php scripts and the plugins directory to a directory that
|
||||||
or set the SMARTY_DIR constant and put your class files in this directory.
|
is in your PHP include_path, or set the SMARTY_DIR constant and put your
|
||||||
|
class files in this directory.
|
||||||
|
|
||||||
* create a "templates" directory, "configs" directory and a "templates_c"
|
* create a "templates", "configs", and a "templates_c" directory,
|
||||||
directory, be sure to set the appropriate directory settings in Smarty for
|
be sure to set the appropriate directory settings in Smarty for them. If they
|
||||||
them. If they are located in the same directory as your application, they
|
are located in the same directory as your application, they shouldn't need to
|
||||||
shouldn't need to be modified. Be sure the "templates_c" directory is
|
be modified. Be sure the "templates_c" directory is writable by your web
|
||||||
writable by your web server user (usually nobody). chown nobody:nobody
|
server user (usually nobody). chown nobody:nobody templates_c; chmod 700
|
||||||
templates_c; chmod 700 templates_c You can also chmod 777 this directory, but
|
templates_c You can also chmod 777 this directory, but be aware of security
|
||||||
be aware of security issues for multi-user systems.
|
issues for multi-user systems. If you are using Smarty's built-in caching,
|
||||||
|
create a "cache" directory and also chown nobody:nobody.
|
||||||
|
|
||||||
* setup your php and template files. A good working example is included to get
|
* setup your php and template files. A good working example is included to get
|
||||||
you started. Also see the QUICKSTART guide for some more examples.
|
you started. Also see the QUICKSTART guide for some more examples.
|
||||||
|
12
QUICKSTART
12
QUICKSTART
@@ -14,12 +14,12 @@ INSTALLATION
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
Unpack the Smarty tarball. You will see four class files: Smarty.class.php,
|
Unpack the Smarty tarball. You will see four class files: Smarty.class.php,
|
||||||
Smarty.addons.php, Smarty_Compiler.class.php and Config_File.class.php. You
|
Smarty.addons.php, Smarty_Compiler.class.php and Config_File.class.php and a
|
||||||
will need to have all four of these files somewhere in your PHP include path,
|
"plugins" directory. You will need to have all four of these files somewhere in
|
||||||
so when you call require("Smarty.class.php") from within your application, it
|
your PHP include path, so when you call require("Smarty.class.php") from within
|
||||||
can find the class. Alternatively, you can set the SMARTY_DIR constant in your
|
your application, it can find the class. Alternatively, you can set the
|
||||||
application, and Smarty will use that directory as the path to the Smarty
|
SMARTY_DIR constant in your application, and Smarty will use that directory as
|
||||||
class files. Be sure the path ends with a slash!
|
the path to the Smarty class files. Be sure the path ends with a slash!
|
||||||
|
|
||||||
Now change directories somewhere inside of your web server document root. For
|
Now change directories somewhere inside of your web server document root. For
|
||||||
this guide, we'll create a directory under the document root named "Smarty",
|
this guide, we'll create a directory under the document root named "Smarty",
|
||||||
|
2
README
2
README
@@ -2,7 +2,7 @@ NAME:
|
|||||||
|
|
||||||
Smarty - the PHP compiling template engine
|
Smarty - the PHP compiling template engine
|
||||||
|
|
||||||
VERSION: 1.5.2
|
VERSION: 2.0
|
||||||
|
|
||||||
AUTHORS:
|
AUTHORS:
|
||||||
|
|
||||||
|
@@ -1,10 +1,34 @@
|
|||||||
2.0
|
2.0
|
||||||
---
|
---
|
||||||
|
|
||||||
This release removes PEAR dependency -- it was mainly a consequence of using
|
This release is a huge milestone for Smarty. Most notable new things are a
|
||||||
Config_File class which was originally written with PEAR in mind but was
|
plugin architecture, PEAR dependancies removed and optimizations that
|
||||||
never integrated into it.
|
drastically improved the performance of Smarty in most cases.
|
||||||
|
|
||||||
|
The plugin architecture allows modifiers, custom functions, compiler functions,
|
||||||
|
prefilters, postfilters, resources an insert functions all to be added by
|
||||||
|
simply dropping a file into the plugins directory. Once dropped in, they are
|
||||||
|
automatically registered by the template engine. This makes user-contributed
|
||||||
|
plugins easy to manage, as well as the internal workings of Smarty easy to
|
||||||
|
control and customize. This new architecture depends on the __FILE__ constant,
|
||||||
|
which contains the full path to the executing script. Some older versions of
|
||||||
|
PHP incorrectly gave the script name and not the full filesystem path. Be sure
|
||||||
|
your version of PHP populates __FILE__ correctly. If you use custom template
|
||||||
|
resource functions, the format of these changed with the plugin architecture.
|
||||||
|
Be sure to update your functions accordingly. See the template resource section
|
||||||
|
of the documentation.
|
||||||
|
|
||||||
|
The PEAR dependancy was removed from Smarty. The Config_File class that comes
|
||||||
|
with Smarty was actually what needed PEAR for error handling which Smarty didn't
|
||||||
|
use, but now everything is self-contained.
|
||||||
|
|
||||||
|
Performance improvements are graphed on the benchmark page, you will see that
|
||||||
|
overall performance has been sped up by as much as 80% in some cases.
|
||||||
|
|
||||||
|
Smarty-cached pages now support If-Modified-Since headers, meaning that if a
|
||||||
|
cached template page has not changed since the last request, a "304 Not
|
||||||
|
Modified" header will be sent instead of resending the same page. This is
|
||||||
|
disabled by default, change the setting of $cache_modified_check.
|
||||||
|
|
||||||
1.5.2
|
1.5.2
|
||||||
-----
|
-----
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
Smarty Resources on the Web:
|
Smarty Resources on the Web:
|
||||||
(if you have something to add, e-mail monte@ispi.net)
|
(if you have something to add, e-mail monte at ispi dot net)
|
||||||
|
|
||||||
Home Page:
|
Home Page:
|
||||||
http://www.phpinsider.com/php/code/Smarty
|
http://www.phpinsider.com/php/code/Smarty
|
||||||
@@ -13,4 +13,3 @@ http://www.mapledesign.co.uk/coding/smarty_table.php
|
|||||||
Misc:
|
Misc:
|
||||||
http://freshmeat.net/projects/smarty/
|
http://freshmeat.net/projects/smarty/
|
||||||
http://www.hotscripts.com/Detailed/8817.html
|
http://www.hotscripts.com/Detailed/8817.html
|
||||||
|
|
||||||
|
@@ -96,7 +96,7 @@ class Smarty
|
|||||||
var $cache_handler_func = null; // function used for cached content. this is
|
var $cache_handler_func = null; // function used for cached content. this is
|
||||||
// an alternative to using the built-in file
|
// an alternative to using the built-in file
|
||||||
// based caching.
|
// based caching.
|
||||||
var $check_if_modified = false; // respect If-Modified-Since headers on cached content
|
var $cache_modified_check = false; // respect If-Modified-Since headers on cached content
|
||||||
|
|
||||||
|
|
||||||
var $default_template_handler_func = ''; // function to handle missing templates
|
var $default_template_handler_func = ''; // function to handle missing templates
|
||||||
@@ -515,7 +515,7 @@ class Smarty
|
|||||||
|
|
||||||
$_smarty_results .= $this->_generate_debug_output();
|
$_smarty_results .= $this->_generate_debug_output();
|
||||||
}
|
}
|
||||||
if ($this->check_if_modified) {
|
if ($this->cache_modified_check) {
|
||||||
global $HTTP_IF_MODIFIED_SINCE;
|
global $HTTP_IF_MODIFIED_SINCE;
|
||||||
$last_modified_date = substr($HTTP_IF_MODIFIED_SINCE, 0, strpos($HTTP_IF_MODIFIED_SINCE, 'GMT') + 3);
|
$last_modified_date = substr($HTTP_IF_MODIFIED_SINCE, 0, strpos($HTTP_IF_MODIFIED_SINCE, 'GMT') + 3);
|
||||||
$gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';
|
$gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';
|
||||||
|
@@ -2118,7 +2118,7 @@ email: zaphod@slartibartfast.com<br>
|
|||||||
{$smarty} variable can be used to refer to 'section' and
|
{$smarty} variable can be used to refer to 'section' and
|
||||||
'foreach' loop properties. See docs for
|
'foreach' loop properties. See docs for
|
||||||
<link linkend="builtin.functions.section">section</link> and
|
<link linkend="builtin.functions.section">section</link> and
|
||||||
<link linkend="builtin.function.foreach">foreach</link>.
|
<link linkend="builtin.functions.foreach">foreach</link>.
|
||||||
</para>
|
</para>
|
||||||
</sect3>
|
</sect3>
|
||||||
|
|
||||||
|
@@ -96,7 +96,7 @@ class Smarty
|
|||||||
var $cache_handler_func = null; // function used for cached content. this is
|
var $cache_handler_func = null; // function used for cached content. this is
|
||||||
// an alternative to using the built-in file
|
// an alternative to using the built-in file
|
||||||
// based caching.
|
// based caching.
|
||||||
var $check_if_modified = false; // respect If-Modified-Since headers on cached content
|
var $cache_modified_check = false; // respect If-Modified-Since headers on cached content
|
||||||
|
|
||||||
|
|
||||||
var $default_template_handler_func = ''; // function to handle missing templates
|
var $default_template_handler_func = ''; // function to handle missing templates
|
||||||
@@ -515,7 +515,7 @@ class Smarty
|
|||||||
|
|
||||||
$_smarty_results .= $this->_generate_debug_output();
|
$_smarty_results .= $this->_generate_debug_output();
|
||||||
}
|
}
|
||||||
if ($this->check_if_modified) {
|
if ($this->cache_modified_check) {
|
||||||
global $HTTP_IF_MODIFIED_SINCE;
|
global $HTTP_IF_MODIFIED_SINCE;
|
||||||
$last_modified_date = substr($HTTP_IF_MODIFIED_SINCE, 0, strpos($HTTP_IF_MODIFIED_SINCE, 'GMT') + 3);
|
$last_modified_date = substr($HTTP_IF_MODIFIED_SINCE, 0, strpos($HTTP_IF_MODIFIED_SINCE, 'GMT') + 3);
|
||||||
$gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';
|
$gmt_mtime = gmdate('D, d M Y H:i:s', $this->_cache_info['timestamp']).' GMT';
|
||||||
|
Reference in New Issue
Block a user