bosh
Новичок
Smarty: register_resource :db_get_timestamp
Берём код из мануала и децл его переписываем с целью учесть то, что у шаблона может быть несколько версий.
Это чудо шикарно заходит в БД, забирает оттуда шаблон и его парсит.
Проблема в том, что при внесении изменений в этот шаблон (добавлении новой записи в таблицу) - шаблон не перестаривается заново а берётся из templates_c
Возникла мысль что всему виной db_get_timestamp
Согласно мануалу:
(2005-09-29 00:14:10)
Я предположил бы, что если это время отличается от времени прописанном в отпарсеном шаблоне, то должна вызываться функция
db_get_template
Однако она не вызывается и по-прежнему данные берутся из templates_c/%%84^840^84053873%%db%3Aindex.tpl.php
Внутри которого написано
Т.е. время уже "устаревшее" и по идее шаблон должен перегенерится.
Если шаблон физически мочкануть из templates_c то он успешно перегенерится новым контентом.
Собственно вопрос: я что-то не так делаю, или это баг?
Берём код из мануала и децл его переписываем с целью учесть то, что у шаблона может быть несколько версий.
PHP:
function db_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
{
global $DB;
// do database call here to fetch your template,
// populating $tpl_source
//$sql = new SQL;
$sql=$DB->execute("select template
from templates
where template_name='$tpl_name' order by ctime desc limit 1",__FILE__,__LINE__);
if ($DB->numRows($sql)) {
$tpl_source = $DB->result($sql);
return true;
} else {
return false;
}
}
function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
// do database call here to populate $tpl_timestamp.
global $DB;
$sql=$DB->execute("select ctime
from templates
where template_name='$tpl_name' order by ctime desc limit 1",__FILE__,__LINE__);
if ($DB->numRows($sql)) {
$tpl_timestamp = $DB->result($sql);
return true;
} else {
return false;
}
}
function db_get_secure($tpl_name, &$smarty_obj)
{
// assume all templates are secure
return true;
}
function db_get_trusted($tpl_name, &$smarty_obj)
{
// not used for templates
}
// register the resource name "db"
$smarty->register_resource("db", array("db_get_template",
"db_get_timestamp",
"db_get_secure",
"db_get_trusted"));
// using resource from php script
$smarty->display("db:index.tpl");
Проблема в том, что при внесении изменений в этот шаблон (добавлении новой записи в таблицу) - шаблон не перестаривается заново а берётся из templates_c
Возникла мысль что всему виной db_get_timestamp
Согласно мануалу:
В моём случае эта функция выдает правильное время последнего изменения.The second function (в данном случае эта самая) is supposed to retrieve the last modification time of the requested resource (as a UNIX timestamp). The second parameter is a variable passed by reference where the timestamp should be stored. The function is supposed to return true if the timestamp could be succesfully determined, and false otherwise.
(2005-09-29 00:14:10)
Я предположил бы, что если это время отличается от времени прописанном в отпарсеном шаблоне, то должна вызываться функция
db_get_template
Однако она не вызывается и по-прежнему данные берутся из templates_c/%%84^840^84053873%%db%3Aindex.tpl.php
Внутри которого написано
PHP:
<?php /* Smarty version 2.6.7, created on 2005-09-29 00:12:39
compiled from db:index.tpl */ ?>
Т.е. время уже "устаревшее" и по идее шаблон должен перегенерится.
Если шаблон физически мочкануть из templates_c то он успешно перегенерится новым контентом.
Собственно вопрос: я что-то не так делаю, или это баг?