Clear templates and cache
[email protected] (pete M)
| Newsgroups | php.smarty.dev |
|---|---|
| Message-ID | <[email protected]> |
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
>>>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).
--------------------------------------------------------------
## 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
{
/**
* 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