student numbers
[ssproject1617.git] / testcms-final-anon / system / admin / controllers / pages.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 class Pages_controller {
4
5 public function __construct() {
6 $this->admin_url = Config::get('application.admin_folder');
7 }
8
9 public function index() {
10 $pages = Pages::list_all();
11 Template::render('pages/index', array('pages' => $pages));
12 }
13
14 public function add() {
15 if(Input::method() == 'POST') {
16 if(Pages::add()) {
17 return Response::redirect($this->admin_url . '/pages/edit/' . Db::insert_id());
18 }
19 }
20 Template::render('pages/add');
21 }
22
23 public function edit($id) {
24 // find page
25 if(($page = Pages::find(array('id' => $id))) === false) {
26 return Response::redirect($this->admin_url . '/pages');
27 }
28
29 // process post request
30 if(Input::method() == 'POST') {
31 if(Pages::update($id)) {
32 // redirect path
33 return Response::redirect($this->admin_url . '/pages/edit/' . $id);
34 }
35 }
36
37 Template::render('pages/edit', array('page' => $page));
38 }
39
40 }