我想重寫此代碼時沒有太多的「其他」,但仍然保持它的效率,無需檢查事件或在不需要的情況下運行查詢。以較整潔的方式重寫此代碼,沒有那麼多其他的
有人可以提出一個更好的方法來寫這個功能?
public static function fetch($content) {
products_library::init();
self::$cache = $cache = url::assetsPath() . '../cache/soldout_cache';
//check the cache
if (file_exists($cache)) {
$cache_date = filectime($cache);
db::select('date_modified');
db::orderBy('date_modified DESC');
db::limit(1);
$mod_date = db::get('sc_module_products')->fetch(PDO::FETCH_ASSOC);
if ($mod_date) {
$mod_date = strtotime('date_modified');
if ($cache_date >= $mod_date) { //serve the cache
try {
$soldout = filewriter::read($cache);
$soldout = unserialize($soldout);
} catch (Exception $e) {
$soldout = self::query();
}
}
else
$soldout = self::query();
}
else
$soldout = self::query();
}
else
$soldout = self::query();
$data['items'] = $soldout; // print_r($items); exit;
$html = view::load('Product_Display', $data, true);
return $html;
}
感謝
怎麼了downvote? – Arend 2011-06-06 00:49:19
靜態上癮? :) – Nemoden 2011-06-06 00:49:38
沒人是完美的。 – Arend 2011-06-06 01:00:30