mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 11:54:26 +02:00
Added Windows example and a few tweaks
This commit is contained in:
@@ -154,8 +154,8 @@
|
|||||||
<sect1 id="installing.smarty.basic">
|
<sect1 id="installing.smarty.basic">
|
||||||
<title>Basic Installation</title>
|
<title>Basic Installation</title>
|
||||||
<para>
|
<para>
|
||||||
Install the Smarty library files which are in the /libs/ directory of
|
Install the Smarty library files which are in the /libs/ sub directory of
|
||||||
the distribution. These are the PHP files that you SHOULD NOT edit. They
|
the distribution. These are PHP files that you SHOULD NOT edit. They
|
||||||
are shared among all applications and they only get updated when you
|
are shared among all applications and they only get updated when you
|
||||||
upgrade to a new version of Smarty.
|
upgrade to a new version of Smarty.
|
||||||
</para>
|
</para>
|
||||||
@@ -174,18 +174,19 @@ debug.tpl
|
|||||||
</example>
|
</example>
|
||||||
<para>
|
<para>
|
||||||
Smarty uses a PHP constant named
|
Smarty uses a PHP constant named
|
||||||
<link linkend="constant.smarty.dir">SMARTY_DIR</link> which is the system
|
<link linkend="constant.smarty.dir">SMARTY_DIR</link> which is the
|
||||||
file path to the Smarty 'libs/' directory. Basically, if your application
|
<emphasis role="bold">full system file path</emphasis> to the Smarty 'libs/' directory.
|
||||||
|
Basically, if your application
|
||||||
can find the <filename>Smarty.class.php</filename> file, you do not need
|
can find the <filename>Smarty.class.php</filename> file, you do not need
|
||||||
to set <link linkend="constant.smarty.dir">SMARTY_DIR</link>
|
to set the <link linkend="constant.smarty.dir">SMARTY_DIR</link>,
|
||||||
Smarty will figure it out on its own. Therefore, if
|
Smarty will figure it out on its own. Therefore, if
|
||||||
<filename>Smarty.class.php</filename> is not in your include_path, or you
|
<filename>Smarty.class.php</filename> is not in your include_path, or you
|
||||||
do not supply an absolute path to it in your application, then you must
|
do not supply an absolute path to it in your application, then you must
|
||||||
define SMARTY_DIR manually. SMARTY_DIR <emphasis>must</emphasis> include a
|
define SMARTY_DIR manually. SMARTY_DIR <emphasis role="bold">must include a
|
||||||
trailing slash.
|
trailing slash</emphasis>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Here is how you create an instance of Smarty in your PHP scripts:
|
Here's how you create an instance of Smarty in your PHP scripts:
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<example>
|
<example>
|
||||||
@@ -193,8 +194,9 @@ debug.tpl
|
|||||||
<programlisting role="php">
|
<programlisting role="php">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
<?php
|
<?php
|
||||||
require('Smarty.class.php');
|
// NOTE: Smarty has a capital 'S'
|
||||||
$smarty = new Smarty;
|
require_once('Smarty.class.php');
|
||||||
|
$smarty = new Smarty();
|
||||||
?>
|
?>
|
||||||
]]>
|
]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
@@ -206,13 +208,40 @@ $smarty = new Smarty;
|
|||||||
do one of the following:
|
do one of the following:
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<example>
|
||||||
|
<title>Set SMARTY_DIR constant manually</title>
|
||||||
|
<programlisting role="php">
|
||||||
|
<![CDATA[
|
||||||
|
<?php
|
||||||
|
// *nix style (note capital 'S')
|
||||||
|
define('SMARTY_DIR', '/usr/local/lib/php/Smarty-v.e.r/libs/');
|
||||||
|
|
||||||
|
// windows style
|
||||||
|
define('SMARTY_DIR', 'c:/webroot/libs/Smarty-v.e.r/libs/');
|
||||||
|
|
||||||
|
// hack version example that works on both *nix and windows
|
||||||
|
// Smarty is assumend to be in 'includes/' dir under current script
|
||||||
|
define('SMARTY_DIR',str_replace("\\","/",getcwd()).'/includes/Smarty/libs/');
|
||||||
|
|
||||||
|
require_once(SMARTY_DIR . 'Smarty.class.php');
|
||||||
|
$smarty = new Smarty();
|
||||||
|
?>
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
|
||||||
<example>
|
<example>
|
||||||
<title>Supply absolute path to library file</title>
|
<title>Supply absolute path to library file</title>
|
||||||
<programlisting role="php">
|
<programlisting role="php">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
<?php
|
<?php
|
||||||
require('/usr/local/lib/php/Smarty/Smarty.class.php');
|
// *nix style (note capital 'S')
|
||||||
$smarty = new Smarty;
|
require_once('/usr/local/lib/php/Smarty-v.e.r/libs/Smarty.class.php');
|
||||||
|
|
||||||
|
// windows style
|
||||||
|
require_once('c:/webroot/libs/Smarty-v.e.r/libs/Smarty.class.php');
|
||||||
|
|
||||||
|
$smarty = new Smarty();
|
||||||
?>
|
?>
|
||||||
]]>
|
]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
@@ -225,33 +254,22 @@ $smarty = new Smarty;
|
|||||||
<?php
|
<?php
|
||||||
// Edit your php.ini file, add the Smarty library
|
// Edit your php.ini file, add the Smarty library
|
||||||
// directory to the include_path and restart web server.
|
// directory to the include_path and restart web server.
|
||||||
// Then the following should work:
|
// then the following should work:
|
||||||
require('Smarty.class.php');
|
require_once('Smarty.class.php');
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty();
|
||||||
?>
|
?>
|
||||||
]]>
|
]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
|
|
||||||
<example>
|
|
||||||
<title>Set SMARTY_DIR constant manually</title>
|
|
||||||
<programlisting role="php">
|
|
||||||
<![CDATA[
|
|
||||||
<?php
|
|
||||||
define('SMARTY_DIR', '/usr/local/lib/php/Smarty/');
|
|
||||||
require(SMARTY_DIR . 'Smarty.class.php');
|
|
||||||
$smarty = new Smarty;
|
|
||||||
?>
|
|
||||||
]]>
|
|
||||||
</programlisting>
|
|
||||||
</example>
|
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Now that the library files are in place, it's time to setup the Smarty
|
Now that the library files are in place, it's time to setup the Smarty
|
||||||
directories for your application.</para>
|
directories for your application.</para>
|
||||||
<para>
|
<para>
|
||||||
Smarty requires four directories which
|
Smarty requires four directories which
|
||||||
are (by default) named <filename class="directory">'templates/'</filename>,
|
are by default named <filename class="directory">'templates/'</filename>,
|
||||||
<filename class="directory">'templates_c/'</filename>, <filename
|
<filename class="directory">'templates_c/'</filename>, <filename
|
||||||
class="directory">'configs/'</filename> and <filename
|
class="directory">'configs/'</filename> and <filename
|
||||||
class="directory">'cache/'</filename>.
|
class="directory">'cache/'</filename>.
|
||||||
@@ -320,12 +338,12 @@ $smarty = new Smarty;
|
|||||||
<title>Example file structure</title>
|
<title>Example file structure</title>
|
||||||
<screen>
|
<screen>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
/usr/local/lib/php/Smarty/Smarty.class.php
|
/usr/local/lib/php/Smarty-v.e.r/libs/Smarty.class.php
|
||||||
/usr/local/lib/php/Smarty/Smarty_Compiler.class.php
|
/usr/local/lib/php/Smarty-v.e.r/libs/Smarty_Compiler.class.php
|
||||||
/usr/local/lib/php/Smarty/Config_File.class.php
|
/usr/local/lib/php/Smarty-v.e.r/libs/Config_File.class.php
|
||||||
/usr/local/lib/php/Smarty/debug.tpl
|
/usr/local/lib/php/Smarty-v.e.r/libs/debug.tpl
|
||||||
/usr/local/lib/php/Smarty/internals/*.php
|
/usr/local/lib/php/Smarty-v.e.r/libs/internals/*.php
|
||||||
/usr/local/lib/php/Smarty/plugins/*.php
|
/usr/local/lib/php/Smarty-v.e.r/libs/plugins/*.php
|
||||||
|
|
||||||
/web/www.example.com/smarty/guestbook/templates/
|
/web/www.example.com/smarty/guestbook/templates/
|
||||||
/web/www.example.com/smarty/guestbook/templates_c/
|
/web/www.example.com/smarty/guestbook/templates_c/
|
||||||
@@ -376,7 +394,7 @@ chmod 770 /web/www.example.com/smarty/guestbook/cache/
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
We need to create the 'index.tpl' file that Smarty will load. This will be
|
We need to create the 'index.tpl' file that Smarty will load. This will be
|
||||||
located in your <link linkend="variable.template.dir">$template_dir</link>.
|
located in the <link linkend="variable.template.dir">$template_dir</link>.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<example>
|
<example>
|
||||||
@@ -386,7 +404,7 @@ chmod 770 /web/www.example.com/smarty/guestbook/cache/
|
|||||||
|
|
||||||
{* Smarty *}
|
{* Smarty *}
|
||||||
|
|
||||||
Hello, {$name}!
|
Hello, {$name} and welcome to Smarty!
|
||||||
]]>
|
]]>
|
||||||
</screen>
|
</screen>
|
||||||
</example>
|
</example>
|
||||||
@@ -405,10 +423,10 @@ Hello, {$name}!
|
|||||||
</note>
|
</note>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Now lets edit 'index.php'. We'll create an instance of Smarty, assign a
|
Now lets edit 'index.php'. We'll create an instance of Smarty,
|
||||||
template variable and display the 'index.tpl' file. In our example
|
<link linkend="api.assign">assign</link> a
|
||||||
environment, "/usr/local/lib/php/Smarty" is in our include_path. Be sure you
|
template variable and <link linkend="api.display">display</link>
|
||||||
do the same, or use absolute paths.
|
the 'index.tpl' file.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<example>
|
<example>
|
||||||
@@ -418,9 +436,9 @@ Hello, {$name}!
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// load Smarty library
|
// load Smarty library
|
||||||
require('Smarty.class.php');
|
require_once(SMARTY_DIR . 'Smarty.class.php');
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty();
|
||||||
|
|
||||||
$smarty->template_dir = '/web/www.example.com/smarty/guestbook/templates/';
|
$smarty->template_dir = '/web/www.example.com/smarty/guestbook/templates/';
|
||||||
$smarty->compile_dir = '/web/www.example.com/smarty/guestbook/templates_c/';
|
$smarty->compile_dir = '/web/www.example.com/smarty/guestbook/templates_c/';
|
||||||
@@ -449,7 +467,7 @@ $smarty->display('index.tpl');
|
|||||||
</note>
|
</note>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Now load the <filename>index.php</filename> file from your web browser.
|
Now naviagate to the <filename>index.php</filename> file with the web browser.
|
||||||
You should see "Hello, Ned!"
|
You should see "Hello, Ned!"
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
|
Reference in New Issue
Block a user