PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.smarty.general > Is this a good way to setup Smarty?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Is this a good way to setup Smarty?

Réponse
 
LinkBack Outils de la discussion
Vieux 08/11/2005, 10h18   #1
Karl Timmermann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Is this a good way to setup Smarty?

I saw this on the net, and was wondering if this is a good way up to
setup Smarty, DB, etc., and then each of my pages will require_once
the attached file. Thanks!






  Réponse avec citation
Vieux 08/11/2005, 10h31   #2
Raz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] Is this a good way to setup Smarty?

Sorry to be paranoid, but it might be better if you used pastebin,
rather than send attachments...

raz
  Réponse avec citation
Vieux 08/11/2005, 16h21   #3
Pedro
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is this a good way to setup Smarty?

Interesting setup you have as its similar to mine .. so I thought's I'd
add variations so we can compare .. for fun ;-)

This setup is for a local lan server as the test machine and a managed
(ie we run it) host for production

Here's the way I would do it !

Karl Timmermann wrote:
> I saw this on the net, and was wondering if this is a good way up to
> setup Smarty, DB, etc., and then each of my pages will require_once the
> attached file. Thanks!
>
>
>
>
> ------------------------------------------------------------------------
>
> <?PHP
> /**
> * set_env.php
> * @author Tom Anderson <toma@etree.org>
> * @version 2.5
> *
> * This script sets up smarty, pear, and all other
> * global settings for a php application.
> */


// Site key needs to be unquie for this project/web..
// locally this is the *nix user name for project
// this is used in $_SESSION[SITE_KEY]['variable'] for example so that
// the same value cannot be set somewhere else..
// eg two applications on the same web server using $_SESSION['user_id']
define('SITE_KEY','a_site');

// name of TEST_SERVER.
// This is used to switch on dev mode on local server/ off on production
define('TEST_SERVER', 'lan_test_server');

> // db connect info
> $dsn = 'mysql://root:root@localhost/database';



// create some path based for live vs production server
if($_SERVER['SERVER_NAME'] == TEST_SERVER){
// dev server settings
error_reporting(E_ALL);

// above $dsn type was confusing to one member of my team !!
$DB['type'] = 'mysql';
$DB['host'] = 'localhost';
$DB['user'] = 'root';
$DB['pass'] = 'secret';
$DB['db'] = 'dbatase';
// dynamic constant cant be changed later in script
define('WEB_ROOT', 'http://'.TEST_SERVER.'/~'.SITE_KEY.'/');
// location of lib files .. local user account
// - NO trailing slash
define('LIBS_ROOT','/home/libs_user/public_html');
// path to shared compile dir
define('SMARTY_COMPILE_DIR','/home/dev/smarty_shared_compile_dir/');

}else{
error_reporting(E_ALL ^ E_NOTICE);
$DB['type'] = 'mysql';
$DB['host'] = '127.0.0.1';
$DB['user'] = 'account';
$DB['pass'] = 'anothersecret';
$DB['db'] = 'account_database';
// dynamic constant cant be changed later in script
define('WEB_ROOT', 'http://www.mysite.org/subdirifneeded/');
// libs directory of ftp account
// - NO trailing slash
define('LIBS_ROOT','/home/ftp_libs_user');
// path to shared compile dir
define('SMARTY_COMPILE_DIR','/home/smarty_shared_compile_dir/');

}

// path to smarty
define('SMARTY_DIR',LIBS_ROOT.'/Smarty-2.6.10/libs/');

>
> // Setup include path
> $web_root = 'http://www.mysite.org/subdirifneeded/';



> $app_root = '/home/mysite/projects/myapp/';

// swaps windows file path to *nix flavour or current path
define('APP_ROOT', str_replace('\\','/',realpath('.')).'/' );

> # note: sometimes pear is installed at /usr/local/lib/php/ but I
> # recommend getting a copy that is local to your application so
> # you can more easily controll when pear code is updated.
> $pear = $app_root . '/pear/';

$pear = APP_ROOT.'/pear/';

//I use ADODB so I'd do
define('ADODB_DIR',LIBS_ROOT.'/adodb464/');


> //---------------------------------------
> //--- end user edit
>
> // Path to .ihtml (template) files
> define('TEMPLATE_DIR', "$app_root/ihtml/");

// I dont declare this an use templates/ by default


> $delim = (PHP_OS == "WIN32" || PHP_OS == "WINNT") ? ';': ':';
> ini_set('include_path', ".{$delim}$pear{$delim}$app_root/include{$delim}$app_root");

// dont like the includes path as it can be confusing
// to developers who dont nderstand where things come form
>
> // Set magic quotes based on database type. If using either of these and using odbc,
> // you will need to set this by hand.
> // You should be able to safely comment this out if your system is setup right.
> ini_set('magic_quotes_sybase', ($dbType == 'mssql' || $dbType == 'sybase') ? '1': '0');
>
> // Include pear database handler, auth object (remove if not used), and smarty
> require_once 'DB.php';

require_once(LIBS_ROOT.'adodb.inc.php');
require_once(LIBS_ROOT.'adodb-errorhandler.inc.php');

> require_once 'smarty/Smarty.class.php';

require_once(SMARTY_DIR.'Smarty.class.php');
>
> // Change error handling as necessary
> // PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or PEAR_ERROR_CALLBACK
> // PEAR::setErrorHandling(PEAR_ERROR_PRINT);
> PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errhndl');
> function errhndl ($err) {
> echo '<pre>' . $err->message;
> print_r($err);
> die();
> }
>
> // Connect to the database and set fetch mode as necessary. Include db extension as needed
> // The next two lines can be safely commented if your system is setup right.
> $extension = "php_$dbType" . (strpos(PHP_OS, "WIN") >= 0 ? ".dll" : ".so");
> if (!function_exists($dbType . '_connect')) dl($extension);

// nice touch .. like the above
// with $dbType swapped to $DB['type']
>
> // Connect to the database
> $db = DB::connect($dsn);
> $db->setFetchMode(DB_FETCHMODE_ASSOC); // Other modes possible; I find assoc best.
> $db->setOption('optimize', 'portability'); // This is really useful for me personally but may not be for everyone.
>

// adodb flavour
$db = &ADONewConnection('mysql');
$db->PConnect($DB['host'],$DB['user'],$DB['pass'],$DB['db']);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
unset($DB); // only paranoid survive

> // Setup template object - NOTE: in this example, 'smarty' is a symlink to
> // the smarty directory. This allows you to upgrade Smarty without changing code.
> $t = new smarty;

$smarty = new Smarty(); // :-)
> $t->template_dir = TEMPLATE_DIR;

// i use the default templates/ dir
> // For other compile and cache directory options, see the comment by Pablo Veliz at the bottom of this article.
> $t->compile_dir = $app_root . '/compile';

$smarty->compile_dir = SMARTY_COMPILE_DIR;
> $t->cache_dir = $app_root . '/cache';
> // Because you should never touch smarty files, store your custom smarty functions, modifiers, etc. in /include
> $t->plugins_dir = array($app_root . '/include', $app_root . '/smarty/plugins');

// append other paths
// path to "stock" plugins created
$smarty->plugins_dir[] = LIBS_DIR.'/smarty_shared_plugins/';
// path to custom local plugins
$smarty->plugins_dir[] = APP_ROOT.'/libs/custom_smarties/';
>
> // Change comment on these when you're done developing to improve performance
> $t->force_compile = true;

$smarty->force_compile = $_SERVER['SERVER_NAME'] == TEST_SERVER;

// additional settings
$smarty->debugging = $_SERVER['SERVER_NAME'] == TEST_SERVER;
$smarty->compile_id = SITE_KEY;
$smarty->use_sub_dirs = ini_get('safe_mode');
$smarty->compile_check = true;


interesting stuff ..

pete

> //$t->caching = true;
>
> ## GLOBALS: $db, $t
> session_start();
>
> /* BEGIN USER AUTH - totally optional */
> // Add user authentication here if you want
> // This example uses pear::Auth
> require_once 'Auth/Auth.php';
> $a = new Auth(
> 'DB',
> array(
> 'table' => 'users',
> 'usernamecol' => 'login',
> 'passwordcol' => 'password',
> 'dsn' => $dsn
> ),
> 'login_function_name',
> true
> );
>
> // Use case insensitive login
> if (isset($_POST['username'])) $_POST['username'] = strtoupper($_POST['username']);
>
> // Check for logout
> if ($_REQUEST['logout'] && $a->getAuth()) {
> $a->start();
> $a->logout();
> session_destroy();
> header("Location: $web_root");
> exit();
> }
>
> // Init the session for this user and authorize.
> $a->start();
> // You could use a global '$require_login = 1;' before 'require_once 'set_env.php';'
> // then check for it here so not all pages require login
> if (!$a->getAuth()) {
> die();
> }
> /* END USER AUTH */
>
> // Assign any global smarty values here.
> $t->assign('web_root', $web_root);
> ?>
>
>
> ------------------------------------------------------------------------
>
>

  Réponse avec citation
Vieux 09/11/2005, 04h35   #4
boots
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] Is this a good way to setup Smarty?

--- Raz <raz.net@gmail.com> wrote:
> Sorry to be paranoid, but it might be better if you used pastebin,
> rather than send attachments...
>
> raz


On a mailing list?? Content at a pastebin doesn't last that long. There
is no problem sending text attatchments that I am aware of.

Boots




__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
  Réponse avec citation
Vieux 09/11/2005, 08h31   #5
Raz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] Is this a good way to setup Smarty?

Well I don't open attachments from a mailing list, period - Contents
on pastebin can last up to 30 days as far as I know.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 21h00.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15999 seconds with 13 queries