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

Estendendo a configuração

Esta é uma continuação da instalação básica, por favor leia a instalação básica primeiro!

Uma forma um pouco mais flexível de configurar o Smarty é estender a classe e inicializar seu ambiente de Smarty. Então, ao invés de configurar caminhos de diretórios repetidamente, preencher as mesmas variáveis, etc., nós podemos fazer isso para facilitar. Vamos criar um novo diretório "/php/includes/guestbook/" e criar um novo arquivo chamado "setup.php". Em nosso ambiente de exemplo, "/php/includes" está em nosso include_path. Certifique-se de que você também definiu isto, ou use caminhos de arquivos absolutos.

Example 2.10. Editando /php/includes/guestbook/setup.php


<?php
// Carrega a biblioteca Smarty
require('Smarty.class.php');

// O arquivo setup.php é um bom lugar para carregar
// arquivos necessarios para a aplicação e você
// pode faze-lo aqui mesmo. Um exemplo:
// require('guestbook/guestbook.lib.php');

class Smarty_GuestBook extends Smarty {

    function Smarty_GuestBook()
    {

        // Construtor da classe.
        // Este é chamado a cada nova instância.

        $this->Smarty();

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

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

}
?>

     

Agora vamos alterar o arquivo index.php para usar o setup.php:

Example 2.11. Editando /web/www.example.com/docs/guestbook/index.php


require('guestbook/setup.php');

$smarty = new Smarty_GuestBook;

$smarty->assign('nome','Thomas');

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

Agora você pode ver que é extremamente simples criar uma instância do Smarty, apenas use Smarty_GuestBook que automaticamente inicializa tudo para a nossa aplicação.

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 11 plus 13? (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