public function p($action = null, $id = null) { switch ($action) { case 'news': if (is_post()) { $gbn = new \app\models\GbNews(); $data = array('title' => $_POST['title'], 'content' => $_POST['content']); if ($_POST['active'] === 'on') { $data['active'] = 1; } else { $data['active'] = 0; } if (!empty($_POST['action'])) { $data['id'] = $_POST['id']; $gbn->update($data); cache_forgot('home.gbnews'); cache_forgot('p.gbn.' . $data['id']); } else { $gbn->create($data); cache_forgot('home.gbnews'); } return redirect('admin/p/news'); } else { $gbn = new \app\models\GbNews(); $gbn = $gbn->all(); $data = empty($gbn) ? array() : $gbn; return $this->view('admin/gbnews', compact('data')); } break; case 'write': if (!empty($id)) { $id = intval($id); $news = new \app\models\GbNews(); $news = $news->getNews($id); if (empty($news)) { return $this->view('errors/404'); } return $this->view('admin/gbnews_write', compact('news')); } return $this->view('admin/gbnews_write'); break; case 'destroy': echo $_POST['id']; if (is_post()) { $news = new \app\models\GbNews(); $news->remove($_POST['id']); } break; default: return redirect('admin'); break; } }
public function getJson() { $news = cache_remember('p.getJson.news.' . user('major'), function () { $news = new \app\models\News(); return json_encode($news->getNewsList()); }); $user = cache_remember('user.get.members.' . user('major'), function () { $user = new \app\models\User(); return json_encode($user->getMembers(true)); }); $gbnews = cache_remember('home.gbnews', function () { $gbnews = new \app\models\GbNews(); return json_encode($gbnews->lists(6)); }); echo '{ "news":' . $news . ', "users":' . $user . ', "gbnews":' . $gbnews . ' }'; }
public function gbn($id) { $ex = explode('-', $id); if (preg_match('/^[0-9]+$/', $ex['0'])) { $data = cache_remember('p.gbn.' . $ex['0'], function () use($ex) { $news = new \app\models\GbNews(); return $news->getNews($ex['0']); }); if (!is_null($data)) { return $this->view('gbnews', compact('data')); } } return $this->view('errors/404'); }