Clear templates and cache
| From: | pete M | Date: | Fri, 09 Jul 2004 10:04:30 +0000 |
| Subject: | Clear templates and cache | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-2475@lists.php.net to get a copy of this message | ||
Following on from the opcode posting....
One of the little niggles in upgrading Smarty is having to clear the templates_c and cache directories.
The following postings by boots and Jan Rosier seem to resolve the problem. Could this not go in the official Smarty ??
wishfully thinking
Pete
--------------------------------------------------------------
## xo boots
-------------------------------------------------------------- ## Jan Rosier I think this has been on the list before, but anyway here is a example howto extend Smarty to do this <?php /** * Template object... * http://smarty.php.net/ */ require_once 'Smarty/2.6.3/Smarty.class.php'; class Smarty_Extension extends Smarty {In my custom Smarty class, for example, I have it track the version of the files in the cache/compiled directories by writing a version file and comparing it to the running version of Smarty. It will clear the directory on a mismatch (and then rewrite the version file).
/**
* Constructor
*
* @access public
*
* @return void
*/
function Smarty_Extension()
{
parent::Smarty();
$this->checkVersion();
}
/**
* This method checks the current version of Smarty. On different
* versions the compiled and cached templates are deleted.
*
* @access public
*
* @return void
*/
function checkVersion()
{
$fname = $this->compile_dir . '/.version-' . $this->_version;
if (!file_exists($fname)) {
$this->clear_all_cache();
$this->clear_compiled_tpl();
touch($fname);
}
}
}
$smarty = new Smarty_Extension;
?>
Just my 2 cent,
Jan Rosier