Edit page working
This commit is contained in:
55
controllers/savepage.php
Normal file
55
controllers/savepage.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use Nickyeoman\Validation;
|
||||
$v = new Nickyeoman\Validation\Validate();
|
||||
|
||||
$url_success = '/dashboard';
|
||||
$url_error = '/novaconium/page/edit/' . $post->get('id'); // Redirect back to the page edit form on error
|
||||
|
||||
if ( empty($session->get('username'))) {
|
||||
$redirect->url('/novaconium/login');
|
||||
$messages->error('You are not loggedin');
|
||||
makeitso();
|
||||
}
|
||||
|
||||
// Check Token
|
||||
if ($session->get('token') != $post->get('token')) {
|
||||
$redirect->url('/novaconium/pages');
|
||||
$messages->error('Invalid Token');
|
||||
makeitso();
|
||||
}
|
||||
|
||||
$id = $post->get('id');
|
||||
$slug = $post->get('slug');
|
||||
$title = $_POST['title'];
|
||||
$body = $_POST['body']; // We want it dirty
|
||||
$intro = $_POST['intro']; // We want it dirty
|
||||
|
||||
if ( empty( $post->get('draft') ) ) {
|
||||
$draft = 0;
|
||||
} else {
|
||||
$draft = 1;
|
||||
}
|
||||
|
||||
if ( empty($id) || empty($slug) || empty($body) ) {
|
||||
$messages->error('One of the fields was empty.');
|
||||
$redirect->url($url_fail);
|
||||
makeitso();
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$query = "UPDATE `pages` SET `title` = ?, `slug` = ?, `body` = ?, `intro` = ?, `draft` = ?, `updated` = NOW() WHERE `id` = ?";
|
||||
$params = [$title, $slug, $body, $intro, $draft, $id];
|
||||
|
||||
$db->query($query, $params);
|
||||
|
||||
$messages->notice('Page Saved');
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
$messages->notice($e->getMessage());
|
||||
|
||||
}
|
||||
|
||||
$redirect->url('/novaconium/page/edit/' . $id);
|
||||
Reference in New Issue
Block a user