There is a config.php code:

<? require_once($config['basedir'].'/smarty/libs/Smarty.class.php'); require_once($config['basedir'].'/libraries/adodb/adodb.inc.php'); $smarty = new Smarty(); $smarty->compile_dir = $config['basedir']."/temporary"; $smarty->template_dir = $config['basedir']."/themes"; $smarty->assign('baseurl', $config['baseurl']); for ($i=0; $i<count($lang); $i++) { $smarty->assign('lang'.$i, $lang[$i]); } ?> 

This code is included in the root index.php (and everywhere where templates are needed)

 <?php include("include/config.php"); $smarty->assign('news',$news); //TEMPLATES BEGIN $smarty->display('header.tpl'); $smarty->display('index.tpl'); $smarty->display('footer.tpl'); ?> 

Is it possible to create an instance of the Smarty class everywhere? (i.e. include everywhere config.php with $ smarty = new Smarty (); ) Ie always use memory per class.

    1 answer 1

    Is it possible to create an instance of the Smarty class everywhere? (i.e. include everywhere config.php with $smarty = new Smarty(); ) Ie always use memory per class.

    Do you know any other alternative ways? This is a very common way, and in general, not only for Smarty.

    PS: the transfer of the Nth number of variables looks rather logical, instead of passing a simple array to the template.

     $smarty->assign('lang'.$i, $lang[$i]); 
    • the data array is read from the file, but the MySQL query is not executed - Vytas
    • @Vytas and what's the difference where it comes from? - teran
    • Well, you can pass an array ... - Vytas