10 lis 2017

Przykład uruchomienia smartów

require_once('/app/config.php');
require_once('/app/smarty-3.1.29/libs/Smarty.class.php');

$smarty=new Smarty;
$smarty->template_dir = '/app/templates/';
$smarty->compile_dir = '/app/data/smarty/templates_c/';
$smarty->cache_dir = '/app/data/smarty/cache/';
$smarty->config_dir = '/app/data/smarty/config/';
$smarty->caching= false;
$smarty->force_compile=true;
//$smarty->force_compile=false;
$smarty->configLoad('pl.conf', 'index');
$smarty->left_delimiter = '!{';
$smarty->right_delimiter = '}!';

$data_to_send=$smarty->fetch('index.html');

header("Connection: close");
ignore_user_abort(true);
header('Content-type: text/html; charset='.$config['encoding']);
header("Content-Length: ".mb_strlen($data_to_send, $config['encoding']));

echo $data_to_send;
30 cze 2010

Przeformatowanie daty za pomoca funkcji str_pad

php:

$tstartdate = '2010-7-1';
$a_tstartdate = explode('-', $tstartdate);
$data_sd['d'] = str_pad($a_tstartdate[2], 2, '0', STR_PAD_LEFT);
$data_sd['m'] = str_pad($a_tstartdate[1], 2, '0', STR_PAD_LEFT);
$data_sd['y'] = $a_tstartdate[0];

smarty:

$smarty->assign('sd_data', $data_sd);

template:
Data wyjazdu:

<input type="text" value="!{$sd_data.d}!" disabled="disabled" size="2" />
<input type="text" value="!{$sd_data.m}!" disabled="disabled" size="2" />
<input type="text" value="!{$sd_data.y}!" disabled="disabled" size="4" />

wynik:
Data wyjazdu: 01 07 2010