diff --git a/NEWS b/NEWS
index 44f8944a..87c51a41 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,4 @@
+ - move debug.tpl to SMARTY_DIR, add to constructor (Monte)
- fixed warning message in function.assign_debug_info (Monte)
- fixed $template_dir, $compile_dir, $cache_dir, $config_dir
to respect include_path (Monte)
diff --git a/Smarty.class.php b/Smarty.class.php
index d89154c1..61219ad3 100644
--- a/Smarty.class.php
+++ b/Smarty.class.php
@@ -71,7 +71,8 @@ class Smarty
// (relative to Smarty directory)
var $debugging = false; // enable debugging console true/false
- var $debug_tpl = 'file:debug.tpl'; // path to debug console template
+ var $debug_tpl = ''; // path to debug console template
+ // (this gets set in the constructor)
var $debugging_ctrl = 'NONE'; // Possible values:
// NONE - no debug control allowed
// URL - enable debugging when keyword
@@ -210,6 +211,8 @@ class Smarty
}
}
}
+ // look for debug template in the SMARTY_DIR
+ $this->debug_tpl = SMARTY_DIR.'debug.tpl';
}
diff --git a/demo/templates/debug.tpl b/debug.tpl
similarity index 100%
rename from demo/templates/debug.tpl
rename to debug.tpl
diff --git a/docs/getting-started.sgml b/docs/getting-started.sgml
index ba3fa2c5..f63dafc2 100644
--- a/docs/getting-started.sgml
+++ b/docs/getting-started.sgml
@@ -116,78 +116,158 @@
Installing Smarty
- Installing Smarty is fairly straightforward, there are a few things to be
- aware of. Smarty creates PHP scripts from the templates. This usually means
- allowing user "nobody" (or whomever the web server runs as) to have
- permission to write the files. Each installation of a Smarty application
- minimally needs a templates directory and a compiled templates directory.
- If you use configuration files you will also need a directory for those. By
- default these are named "templates", "templates_c" and "configs"
- respectively. "templates_c" needs to be writable by the web server user. If
- you plan on using caching, you will need to create a "cache" directory,
- also with permission to write files.
+ First install the Smarty library files. These are the PHP files that you DO
+ NOT edit. They only get updated when you upgrade to a new version of Smarty.
+ These files are shared among all applications installed on your server that
+ utilize Smarty.
Technical Note
- You can get around the need to allow the web server
- user write access to compile templates. Smarty needs to compile the
- templates only once. This can be done from the command line, using the
- CGI version of PHP. example: "php -q index.php". Once the templates are
- compiled, they should run fine from the web environment. If you change
- a template, you must recompile from the command line again. If you do
- not have the CGI version of PHP available and you are concerned about
- world-writable directory access, you can chmod 777 the compile_dir, let
- the templates compile once as the web server user, then change the
- directory mode to 755. If you are using the caching feature of Smarty,
- the cache directory must always have write access for the web server
- user.
+ We highly recommend you do not edit the Smarty files unless you know what
+ you're doing. This makes upgrades much easier for you. You DO NOT need to
+ edit these files to configure your applications! Use an instance of the
+ Smarty class, which we'll get to in the sample setup below.
-
- Technical Note
+
- If you do not have access to the php.ini file, you can
- change non-server settings (such as your include_path) with the
- ini_set() command (available in PHP 4.0.4 or later.) example:
- ini_set("include_path",".:/usr/local/lib/php");
+ Here is a list of the library files that come with Smarty:
-
-
- Copy the Smarty.class.php, Smarty.addons.php and Config_File.class.php
- scripts to a directory that is in your PHP include_path. NOTE: PHP will
- try to create a directory alongside the executing script called
- "templates_c". Be sure that directory permissions allow this to happen.
- You will see PHP error messages if this fails. You can also create the
- directory yourself before hand, and change the file ownership
- accordingly. See below.
-
-
- Technical Note
-
- If you don't want to use include_path to find the
- Smarty files, you can set the SMARTY_DIR constant to the full path to
- your Smarty library files. Be sure the path ends with a slash!
-
-
- Example of installing Smarty
+ Smarty library files list
-# be sure you are in the web server document tree
-# this assumes your web server runs as user "nobody"
-# and you are in a un*x environment
-gtar -zxvf Smarty-[version].tar.gz
-mkdir templates_c
-chown nobody:nobody templates_c
-chmod 700 templates_c
-# if you are using caching, do the following
-mkdir cache
-chown nobody:nobody cache
-chmod 700 cache
+Smarty.class.php
+Smarty_Compiler.class.php
+Config_File.class.php
+/plugins/(all files)
+
- Next, try running the index.php script from your web browser.
+ Place these library files in a directory located within your PHP
+ include_path. Your include_path is usually set in your php.ini file, and you
+ can get your current include_path setting from the phpinfo() function. Call
+ Smarty in your applications like this:
+
+
+ Loading Smarty library files from include_path
+
+// Smarty.class.php will be found in your include_path
+require('Smarty.class.php');
+$smarty = new Smarty;
+
+
+
+ If you would like to place your library files outside of your include path,
+ you must supply the absolute path in your application via the SMARTY_DIR
+ constant. SMARTY_DIR must end with a slash. Lets say we place our Smarty
+ library files in /usr/local/lib/php/Smarty/.
+
+
+
+ Loading Smarty library files directly
+
+define(SMARTY_DIR,'/usr/local/lib/php/Smarty/');
+require(SMARTY_DIR.'Smarty.class.php');
+$smarty = new Smarty;
+
+
+
+ Now we need to setup the directories for our application. These are
+ $template_dir, $compile_dir, $config_dir and $cache_dir. It is your
+ discretion to have your applications share any of these directories, or
+ make them separate. None of these directories need be in the document root
+ of your web server, so keep them out of there to avoid the issue of prying
+ eyes getting to these files directly with a browser.
+
+
+ Lets take a look at an example of a complete file structure for all of our
+ files:
+
+
+
+ Example file structure
+
+/usr/local/lib/php/Smarty/Smarty.class.php
+/usr/local/lib/php/Smarty/Smarty_Compiler.class.php
+/usr/local/lib/php/Smarty/Config_File.class.php
+/usr/local/lib/php/Smarty/plugins/*.php
+
+/web/www.mydomain.com/smarty/templates/
+/web/www.mydomain.com/smarty/templates_c/
+/web/www.mydomain.com/smarty/configs/
+/web/www.mydomain.com/smarty/cache/
+
+/web/www.mydomain.com/docs/myapp/index.php
+
+
+
+ Smarty will need write access to the $compile_dir and $cache_dir, so be sure
+ the web server user can write to them. This is usually user "nobody" and
+ group "nobody". For OS X users, the default is user "web" and group "web".
+
+
+ Setting file permissions
+
+
+chown nobody:nobody /web/www.mydomain.com/smarty/templates_c/
+chmod 550 /web/www.mydomain.com/smarty/templates_c/
+
+chown nobody:nobody /web/www.mydomain.com/smarty/cache/
+chmod 550 /web/www.mydomain.com/smarty/cache/
+
+/web/www.mydomain.com/docs/index.php
+
+
+
+ In this example, index.php is in our document root under the subdirectory
+ "myapp". Lets edit this file and call a Smarty template.
+
+
+
+ Editing index.php
+
+
+// contents of /web/www.mydomain.com/docs/myapp/index.php
+
+define(SMARTY_DIR,'/usr/local/lib/php/Smarty/');
+require(SMARTY_DIR.'Smarty.class.php');
+
+$smarty = new Smarty;
+
+/*
+ NOTE: the following four lines do not need to be set if
+ /web/www.mydomain.com/smarty/ is in your include_path.
+*/
+
+$smarty->template_dir = '/web/www.mydomain.com/smarty/templates/';
+$smarty->compile_dir = '/web/www.mydomain.com/smarty/templates_c/';
+$smarty->config_dir = '/web/www.mydomain.com/smarty/configs/';
+$smarty->cache_dir = '/web/www.mydomain.com/smarty/cache/';
+
+$smarty->display('index.tpl');
+
+
+
+ Before we execute this, we need to create the index.tpl file that Smarty will
+ load. This will be located in your $template_dir.
+
+
+
+ Editing index.tpl
+
+
+{* contents of /web/www.mydomain.com/smarty/templates/index.tpl *}
+
+Hello World!
+
+
+
+ Now load the index.php file from your web browser. You should see "Hello
+ World!" That's it for the basic setup for Smarty!
+
+
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index d89154c1..61219ad3 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -71,7 +71,8 @@ class Smarty
// (relative to Smarty directory)
var $debugging = false; // enable debugging console true/false
- var $debug_tpl = 'file:debug.tpl'; // path to debug console template
+ var $debug_tpl = ''; // path to debug console template
+ // (this gets set in the constructor)
var $debugging_ctrl = 'NONE'; // Possible values:
// NONE - no debug control allowed
// URL - enable debugging when keyword
@@ -210,6 +211,8 @@ class Smarty
}
}
}
+ // look for debug template in the SMARTY_DIR
+ $this->debug_tpl = SMARTY_DIR.'debug.tpl';
}
diff --git a/templates/debug.tpl b/libs/debug.tpl
similarity index 100%
rename from templates/debug.tpl
rename to libs/debug.tpl