class Home_Controller extends Base_Controller {
public function get_index() {
$posts = Post::with('user')
->join('users', 'users.id', '=', 'posts.post_author')
-> order_by('posts.created_at', 'desc')
->get(array('posts.id', 'posts.support', 'posts.against', 'users.username', 'posts.post_author', 'posts.post_title', 'posts.post_body'));
$data = array();
foreach($posts as $p){
$data[] = array(
'id' => $p -> id,
'support' => $p -> support,
'against' => $p -> against,
'username'=> $p -> username,
'post_author' => $p -> post_author,
'post_title' => $p -> post_title,
'post_body' => $p -> post_body
);
}
return View::make('home.index')
-> with('posts', $data);
}
}
class Home_Controller extends Base_Controller {
public function get_index() {
// 添加静态缓存支持
// 如果不存在静态页缓存就立即缓存
if ( !Cache::has('staticPageCache_home') ) {
$data = array();
$posts = Post::with('user')
->join('users', 'users.id', '=', 'posts.post_author')
-> order_by('posts.created_at', 'desc')
->get(array('posts.id', 'posts.support', 'posts.against', 'users.username', 'posts.post_author', 'posts.post_title', 'posts.post_body'));
foreach($posts as $p){
$data[] = array(
'id' => $p -> id,
'support' => $p -> support,
'against' => $p -> against,
'username'=> $p -> username,
'post_author' => $p -> post_author,
'post_title' => $p -> post_title,
'post_body' => $p -> post_body
);
}
$res = View::make('home.index')
-> with('posts', $data);
Cache::forever('staticPageCache_home', $res);
}
// 返回缓存的数据
return Cache::get('staticPageCache_home');
}
}
// 刷新首页缓存(暂时只支持首页)
public function get_refreshcache() {
/*
@var $GID admin组id
*/
$GID = 1;
if ( Auth::user() -> gid === 1 ) {
$data = array();
$posts = Post::with('user')
->join('users', 'users.id', '=', 'posts.post_author')
-> order_by('posts.created_at', 'desc')
->get(array('posts.id', 'posts.support', 'posts.against', 'users.username', 'posts.post_author', 'posts.post_title', 'posts.post_body'));
foreach($posts as $p){
$data[] = array(
'id' => $p -> id,
'support' => $p -> support,
'against' => $p -> against,
'username'=> $p -> username,
'post_author' => $p -> post_author,
'post_title' => $p -> post_title,
'post_body' => $p -> post_body
);
}
$res = View::make('home.index')
-> with('posts', $data);
Cache::forever('staticPageCache_home', $res);
return '刷新首页缓存成功!';
}
return '对不起,只有管理员组才可进行此操作!';
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有