اخوي الطريقة سهله بس تحتاج منك بعض التفكير وتتبع الكود
الحين حنا نستعمل الكلاس class.template.php في التعامل مع القوالب وايضا نستخدم الدالة display
نروح لdisplay تلقاها تستعمل fetch وفي fetch تلقا فيها اهم شئ _fetch_compile
وهي اللي فيها التعديل
كود PHP:
function _fetch_compile($file) {
$this->template_dir = $this->_get_dir($this->template_dir);
$name = md5($this->template_dir.$file).'.php';
if ($this->cache) {
array_push($this->_cache_info['template'], $file);
}
if (!$this->force_compile && file_exists($this->compile_dir.'c_'.$name) && (filemtime($this->compile_dir.'c_'.$name) > filemtime($this->template_dir.$file))) {
ob_start();
include($this->compile_dir.'c_'.$name);
$output = ob_get_contents();
ob_end_clean();
error_reporting($this->_error_level);
return $output;
}
if ($this->template_exists($file)) {
$f = fopen($this->template_dir.$file, "r");
$size = filesize($this->template_dir.$file);
if ($size > 0) {
$file_contents = fread($f, filesize($this->template_dir.$file));
} else {
$file_contents = "";
}
$this->_file = $file;
fclose($f);
} else {
$this->trigger_error("file '$file' does not exist", E_USER_ERROR);
}
if (!is_object($this->_compile_obj)) {
require_once("class.compiler.php");
$this->_compile_obj = new compiler;
}
$this->_compile_obj->left_tag = $this->left_tag;
$this->_compile_obj->right_tag = $this->right_tag;
$this->_compile_obj->plugin_dir = &$this->plugin_dir;
$this->_compile_obj->template_dir = &$this->template_dir;
$this->_compile_obj->_vars = &$this->_vars;
$this->_compile_obj->_confs = &$this->_confs;
$this->_compile_obj->_plugins = &$this->_plugins;
$this->_compile_obj->_linenum = &$this->_linenum;
$this->_compile_obj->_file = &$this->_file;
$output = $this->_compile_obj->_compile_file($file_contents);
$f = fopen($this->compile_dir.'c_'.$name, "w");
fwrite($f, $output);
fclose($f);
ob_start();
eval(' ?>' . $output . '<?php ');
$output = ob_get_contents();
ob_end_clean();
error_reporting($this->_error_level);
return $output;
}
طبعا فكرتها تعطيها اسم القالب تبحث عنه في مجلد القوالب اذا لم تجده تصدر خطأ ..
وايضا الفكرة الثانية هناك لكل ملف filemtime وهو وقت اخر مرة تم تعديل الملف او وقت انشاء الملف
يقارن filemtime حق الملف المعالج وحق القالب
اذا القالب اجدد يقوم بانشاء الملف المعالج من جديد
هذه هي الفكرة تقريبا ً
طبعا لن أعطيك مافعلت مباشرة بل سأعطيك الفكرة وعليك التطبيق
شف هنا :
كود PHP:
if (!$this->force_compile && file_exists($this->compile_dir.'c_'.$name) && (filemtime($this->compile_dir.'c_'.$name) > filemtime($this->template_dir.$file))) {
في حالة التخزين في جدول لايوجد لدينا filemtime بل نستطيع الاستغناء عنها ب حقل في جدول القوالب نسميه
lastmodify كلما عدلنا القالب نعدل هذا الحقل بوضع فيه قيمة الدالة time();
يعني هذا
كود PHP:
filemtime($this->template_dir.$file)
>>> الشئ الاخر
هذه السطور
كود PHP:
if ($this->template_exists($file)) {
$f = fopen($this->template_dir.$file, "r");
$size = filesize($this->template_dir.$file);
if ($size > 0) {
$file_contents = fread($f, filesize($this->template_dir.$file));
} else {
$file_contents = "";
}
$this->_file = $file;
fclose($f);
} else {
$this->trigger_error("file '$file' does not exist", E_USER_ERROR);
}
نستغني عنها بــ
كود PHP:
$select = mysql_query("select data from template where name = '$file' ");
$select = mysql_fetch_assoc($select);
$file_contents = $select['data'];
$this->_file = $file;
if (!$select )
$this->trigger_error("file '$file' does not exist", E_USER_ERROR);
اتمنى فيه الفائدة ..