Comunitatea PHP Romania
 

 
Extended Setup

Extended Setup

This is a continuation of the basic installation, please read that first!

A slightly more flexible way to setup Smarty is to extend the class and initialize your Smarty environment. So instead of repeatedly setting directory paths, assigning the same vars, etc., we can do that in one place.

Lets create a new directory /php/includes/guestbook/ and make a new file called setup.php. In our example environment, /php/includes is in our include_path. Be sure you set this up too, or use absolute file paths.

Example 2-10. /php/includes/guestbook/setup.php

<?php

// load Smarty library
require('Smarty.class.php');

// The setup.php file is a good place to load
// required application library files, and you
// can do that right here. An example:
// require('guestbook/guestbook.lib.php');

class Smarty_GuestBook extends Smarty {

   function 
Smarty_GuestBook()
   {

        
// Class Constructor.
        // These automatically get set with each new instance.

        
$this->Smarty();

        
$this->template_dir '/web/www.example.com/guestbook/templates/';
        
$this->compile_dir  '/web/www.example.com/guestbook/templates_c/';
        
$this->config_dir   '/web/www.example.com/guestbook/configs/';
        
$this->cache_dir    '/web/www.example.com/guestbook/cache/';

        
$this->caching true;
        
$this->assign('app_name''Guest Book');
   }

}
?>

Now lets alter the index.php file to use setup.php:

Example 2-11. /web/www.example.com/guestbook/htdocs/index.php

<?php

require('guestbook/setup.php');

$smarty = new Smarty_GuestBook();

$smarty->assign('name','Ned');

$smarty->display('index.tpl');
?>

Now you see it is quite simple to bring up an instance of Smarty, just use Smarty_GuestBook() which automatically initializes everything for our application.

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Top membri

Pirahna Pirahna
la birou
carco carco
Bucuresti
Birkoff Birkoff
Bucuresti
Mascka Mascka
Braila
raul_ raul_
whooper whooper
Toronto ON
mihaitha mihaitha
Sibiu
gabysolomon gabysolomon
Bacau
oriceon oriceon
Constanta
garlicinicolae garlicinicolae

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink The eBay Song | Rapidshare and Megaupload | Free Myspace Layouts | Final Fantasy Unlimited | Wire Transfer
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis