Ich bin gerade dabei ein Template system für mich zu schreiben, welches immer 3 dateien compiliert und in einem ordner als php speichert...
also spich eine header, content und footer datei... header und footer wird automatisch dazucompiliert.... wie schaff ich das nun zu überprüfen, ob sich inhaltlich einer template datei was geändert hat, um diese dann neu zu compilieren....
also man kann die klasse erstellen, und einen subdir angeben, in der die tpl dann liegt die aufgerufen wird...
und ich wollte das eigentlich so prüfen:
header
tpl
footer
das ganze als md5 file...
also so: header_5 . tpl_5 . footer_5
und dann gucken ob so eine datei schon existiert, aber irgenwie scheint das nicht so ganz zu klappen.
oder wie würdet ihr das machen?
ich mache es in meinem fall so:
Code: Alles auswählen
/**
* Check if template is compiled or compile it
*
* @param string $_tpl
* @return
*
**/
function display($_tpl)
{
if ($this->_is_compiled($_tpl))
{
$hash_header = md5_file($this->templates_dir . $this->subdir . $this->header . $this->_tpl_Ex);
$hash_footer = md5_file($this->templates_dir . $this->subdir . $this->footer . $this->_tpl_Ex);
$hash_tpl_file = md5_file($this->templates_dir . $this->subdir . $_tpl . $this->_tpl_Ex);
$end_hash = substr($hash_header . $hash_tpl_file . $hash_footer, 10, -60);
include($this->compile_dir . $end_hash . $_tpl . $this->_tpl_Ex . '.php');
}
else
{
die('datei_noch_nicht_compiliert');
if ($this->_compile_file($_tpl))
{
die('compilation erfolgreich');
}
}
}
/**
* Check if Template already compiled
*
* @param string $_tpl
* @return true/false
*
**/
private function _is_compiled($_tpl)
{
$hash_header = md5_file($this->templates_dir . $this->subdir . $this->header . $this->_tpl_Ex);
$hash_footer = md5_file($this->templates_dir . $this->subdir . $this->footer . $this->_tpl_Ex);
$hash_tpl_file = md5_file($this->templates_dir . $this->subdir . $_tpl . $this->_tpl_Ex);
$end_hash = substr($hash_header . $hash_tpl_file . $hash_footer, 10, -60);
if (file_exists($this->compile_dir . $end_hash . $_tpl . $this->_tpl_Ex . '.php'))
{
return true;
}
else
{
return false;
}
}