tags:

views:

282

answers:

3

What function can I use in PHP for class Smarty which reads a variable's value from the Smarty's config file?

Here's my code:

<?

session_start();

require('libs/Smarty.class.php');

$smarty = new Smarty;

$smarty->config_load("settings.conf");

include('settings.php');
include('meta.php');

$smarty->debugging = false;
$smarty->caching =false;
$smarty->cache_lifetime = 120;



include("categories.php");
include("manufacturers.php");
include("logos.php");

print_r($smarty->getConfigVariable("showCategories"));

close_database_session($dbconn);

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



?>
+2  A: 

With get_config_vars() (you have to load the configuration beforehand with config_load()).

Example from the documentation:

// get loaded config template var #foo#
$myVar = $smarty->get_config_vars('foo');

// get all loaded config template vars
$all_config_vars = $smarty->get_config_vars();

Update (Smarty 3.0 RC1):

For Smarty 3.0 RC1 it is

$smarty->configLoad($config_file, $sections = null)
// and
$smarty->getConfigVariable($variable)

Note there is no official documentation yet but the methods available are listed in the included README file.

Felix Kling
here's what I'm getting from the PHP now: Notice: function call 'config_load' is unknown or deprecated. in C:\xampp\htdocs\rondcom\libs\sysplugins\smarty_internal_wrapper.php on line 57I'm using smarty 3.
Ervin
@Ervin: Updated my answer, the methods are listed in the README file.
Felix Kling
It's working, but the error message is being given. But if I put @ in front then everything's fine. Thank you
Ervin
A: 

Hi

here is the simple way to get your smarty assigned config variables

print_r of your $smarty object and note down your config variables

and to get those variables of say "settings.conf"

 $category_title1 = $smarty->_config[0]['vars']['driving_license_category'];

youcan then use as you like it in php

Best Irfan Ahmed

irfan
A: 

I did it using this code:

        $templ->fetch('template_that_loads_config.tpl');
        print_r($templ->_config[0]['vars']);
Tsvetan Filev