Get Smarty

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

Configuration avancée

Ceci est la suite de l'installation de base, veuillez lire cette dernière avant de poursuivre.

Une manière un peu plus commode de configurer Smarty est de faire votre propre classe fille et de l'initialiser selon votre environnement. De la sorte, nous n'aurons plus besoin de configurer à chaques fois les chemins de notre environnement. Créons un nouveau répertoire /php/includes/livredor/ et un nouveau fichier appelé setup.php. Dans notre exemple d'environnement, /php/includes est notre include_path PHP. Assurez-vous de faire la même chose ou alors d'utiliser des chemins absolus.

Example 2.10. Édition de /php/includes/livredor/setup.php


<?php
// charge la librairie Smarty
require('Smarty.class.php');

// le fichier setup.php est un bon
// endroit pour charger les fichiers
// de librairies de l'application et vous pouvez
// faire celà juste ici. Par exemple :
// require('livredor/livredor.lib.php');

class Smarty_livredor extends Smarty {

 function Smarty_livredor() {

 // Constructeur de la classe.
 // Appelé automatiquement à l'instanciation de la classe.

 $this->Smarty();

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

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

}
?>

    

Modifions maintenant le fichier index.php pour qu'il utilise setup.php

Example 2.11. Édition de /web/www.example.com/docs/livredor/index.php


<?php
require('livredor/setup.php');

$smarty = new Smarty_livredor();

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

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

?>

    

Vous savez maintenant qu'il est facile de créer une instance de Smarty, correctement configurée, en utilisant Smarty_livredor() qui initialise automatiquement tout ce qu'il faut pour votre application.

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 9 plus 3? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk