playgrounds (diffrent smarty apps with one smarty installation)

From: Date: Thu, 24 Oct 2002 12:37:24 +0000
Subject: playgrounds (diffrent smarty apps with one smarty installation)
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6227@lists.php.net to get a copy of this message
Hi smarty users, here are some suggestions to set up smarty for more than one smarty application on the same server (i call them playgrounds in the examples): My information are based on smarty-doku, the smarty-Wiki at http://smarty.incutio.com/ and other corresponding links. Directory-structure: smarty (latest version) itself is located at /usr/local/lib/php/Smarty-2.3.0/ and a softlink is set, so that /usr/local/lib/php/Smarty/ points to this directory (easy for further updates). plugins are lacated at /usr/local/lib/php/Smarty/plugins/ (Maybe it is a good idea to keep them seperate to, cause you may have more plugins than the basic ones..) The Web-Server's (Apache2 on FreeBSD) document root is /usr/local/www/data/ from the internet accessible files are stored in /usr/local/www/data/playground /usr/local/www/data/playground1 /usr/local/www/data/playground2 the corresponding smarty files are placed in /usr/local/www/smarty/playground/ /usr/local/www/smarty/playground/templates /usr/local/www/smarty/playground/templates_c /usr/local/www/smarty/playground/cache /usr/local/www/smarty/playground/configs (and are not accessible over the net) (and /usr/local/www/smarty/playground1/ /usr/local/www/smarty/playground1/templates /usr/local/www/smarty/playground1/templates_c /usr/local/www/smarty/playground1/cache /usr/local/www/smarty/playground1/configs and so on...) A global setenv file is located at /usr/local/www/smarty/global_setenv.php It contains the information that is common for all applications: >>>> globlal_setenv.php <<<< <?php // Setup include path require('/usr/local/www/smarty/'.SMARTY_APPNAME.'/local_setenv.php'); define(SMARTY_DIR,'/usr/local/lib/php/Smarty/'); require(SMARTY_DIR.'Smarty.class.php'); class Smarty_Now extends Smarty { function Smarty_Now() { // Class Constructor. These automatically get set with each new instance. $this->template_dir = '/usr/local/www/smarty/'.SMARTY_APPNAME.'/templates/'; $this->compile_dir = '/usr/local/www/smarty/'.SMARTY_APPNAME.'/templates_c/'; $this->config_dir = '/usr/local/www/smarty/'.SMARTY_APPNAME.'/configs/'; $this->cache_dir = '/usr/local/www/smarty/'.SMARTY_APPNAME.'/cache/'; // set caching in the local_setenv.php! $this->caching = CACHING; $this->assign('app_name',SMARTY_APPNAME); } } // Connect to the database require_once 'DB.php'; // PEAR::setErrorHandling(PEAR_ERROR_CALLBACK,'bp_handle_pear_error'); if (DB::isError($db = DB::connect(array( 'username' => $dbUser, 'password' => $dbPass, 'hostspec' => $dbServer, 'database' => $dbDatabase, 'phptype' => $dbType )))) { echo ('Unable to connect to database: ' . DB::errorMessage($db->code)); print_r($db); die(); } $t = new Smarty_Now; // you may change this to $smarty = new Smarty_Now; // but $t is much shorter and i am lazy by nature ?> >>>> end of globlal_setenv.php <<<< A local setenv file is located at /usr/local/www/smarty/playground/local_setenv.php (i don't give examples for playground 2 and 3, ok?) It contains the information, that is needed for only this one application: >>>> /usr/local/www/smarty/playground/local_setenv.php <<<< <?php // database init $dbUser = 'playground'; $dbPass = 'passwd'; $dbServer = 'localhost'; $dbDatabase = 'playground'; $dbType = 'mysql'; // select Caching TRUE or FALSE define(CACHING,"FALSE"); // Client specific variables error_reporting(E_ALL - E_NOTICE); // debug. maybe useful? $smarty->compile_check = true; $smarty->debugging = true; ?> >>>> end of /usr/local/www/smarty/playground/local_setenv.php <<<< Finally the index.php of the application looks like this: >>>> /usr/local/www/data/playground/index.php <<<< <?php define(SMARTY_APPNAME,'playground'); require('/usr/local/www/smarty/global_setenv.php'); ...the programming here... $t->display("index.html"); ?> >>>> end of /usr/local/www/data/playground/index.php <<<< the index.html itself loads a header and a footer that are common to all pages for this project: >>>> /usr/local/www/smarty/playground/templates/index.html <<<< {config_load file=test.conf section="setup"} {* from the smarty doc - example test conf at *} {* /usr/local/lib/php/Smarty/configs/test.conf *} {* but here loaded from *} {* /usr/local/www/smarty/playground/configs/test.conf *} {include file="header.html" title=playground} {* includes /usr/local/www/smarty/playground/templates/header.html *} some html here... {include file="footer.html"} {* includes /usr/local/www/smarty/playground/templates/footer.html *} >>>> end of /usr/local/www/smarty/playground/templates/index.html <<<< my header.html also contains the popup_init (overlib.js), remove it, if you don't want to use the popup function. >>>> /usr/local/www/smarty/playground/templates/header.html <<<< <html> <head> <!-- This webpage is generated by SMARTY php engine --> <title>{$title}</title> <link rel="stylesheet" media="screen" href="/css/screen.css" type="text/css"> <link rel="stylesheet" media="print" href="/css/print.css" type="text/css"> <meta name="DESCRIPTION" content="Information Website"> <meta name="KEYWORDS" content="Elug, LAMP, lamp, linux, apache, mysql, php, php3, php4, monkeytower"> <meta name="AUTHOR" content="Olaf Klein"> <meta name="COPYRIGHT" content="Olaf Klein"> <meta name="LANGUAGE" content="de"> <meta name="AUDIENCE" content="ALL"> <meta name="DISTRIBUTION" content="ALL"> <meta name="PAGE-TOPIC" content="instruction tutorial"> <meta name="ROBOTS" content="ALL"> <meta name="REVISIT-AFTER" content="1 month"> <meta name="REPLY-TO" content="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#109;&#97;&#105;&#108;&#64;&#111;&#108;&#97;&#102;&#45;&#107;&#108;&#101;&#105;&#110;&#46;&#100;&#101;"> <meta http-equiv="CONTENT-LANGUAGE" content="de"> <meta http-equiv="CACHE-CONTROL" content="no-store"> <meta http-equiv="EXPIRES" content="0"> <meta http-equiv="CONTENT-TYPE" content="text/html; CHARSET=iso-8859-1"> <meta name="generator" content="Ulli Meybohms HTML EDITOR"> <link rev="MADE" title="Olaf Klein"> </link> <script language="JavaScript"> <!-- /* Verhindert, dass die Seite als Unterseite eines Frames angezeigt wird */ if(top.frames.length > 0) top.location.href=self.location; //--> </script> </head> <!-- this example is taken from www.linux-root.de/elug/lamp.html --> <body> {popup_init src="/javascripts/overlib.js"} >>> end of /usr/local/www/smarty/playground/templates/header.html <<< finally the footer looks like this: >>>> /usr/local/www/smarty/playground/templates/footer.html <<<< </body> </html> >>> end of /usr/local/www/smarty/playground/templates/footer.html <<< The template file endings are named .html (instead of .tpl) to enable html syntax highlighting in most editors. The basic idea is from toma (http://smarty.incutio.com/?page=toma), i just added the functionality of diffrent playgrounds and stripped out some PEAR settings, since PEAR now comes with MOD_PHP4. Hopefully you find it useful. I am a smarty beginner (comming from FastTemplates). Any comments and suggestions are welcome! thanks for reading this. .olaf klein. -- /\\ monkeytower\\ internet agency telephone: +49(0)201 75001323 faxnumber: +49(0)201 75001324 internet: www.monkeytower.net ________________________________________________________________ Keine verlorenen Lotto-Quittungen, keine vergessenen Gewinne mehr! Beim WEB.DE Lottoservice: http://tippen2.web.de/?x=13

« previous php.smarty.general (#6227) next »