v0.0.6 Made edit and update now works dynamically
This commit is contained in:
parent
256f163771
commit
4024c0dd99
|
@ -1,17 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require "accessControl.php";
|
||||||
require "../../bootstrap.php";
|
require "../../bootstrap.php";
|
||||||
|
|
||||||
use Backend\Model\Post;
|
use Backend\Model\Post;
|
||||||
|
|
||||||
if(isset($_GET['id'])){
|
if(isset($_GET['delete_id'])){
|
||||||
$id = $_GET['id'];
|
$id = $_GET['delete_id'];
|
||||||
$findId = Post::query()->findOrFail($id);
|
$findId = Post::query()->findOrFail($id);
|
||||||
|
|
||||||
if(!$findId->delete()){
|
if(!$findId->delete()){
|
||||||
echo "Error could not delete record";
|
return "Error could not delete";
|
||||||
}else{
|
}else{
|
||||||
header("location: ../../Frontend/home.php?recordDeleted");
|
return "Record deleted";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,4 @@ use Backend\Model\Post;
|
||||||
if(isset($_GET['id'])){
|
if(isset($_GET['id'])){
|
||||||
$id = $_GET['id'];
|
$id = $_GET['id'];
|
||||||
$post = Post::query()->find($id);
|
$post = Post::query()->find($id);
|
||||||
|
|
||||||
if($post){
|
|
||||||
echo $post;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,12 @@ if (!isset($_SESSION['token'])) {
|
||||||
header("location: ../../Frontend/index.php?login=notloggedin");
|
header("location: ../../Frontend/index.php?login=notloggedin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
header('Content-Type: application/json;charset=UTF-8');
|
header('Content-Type: application/json;charset=UTF-8');
|
||||||
echo "<pre>";
|
|
||||||
$data = Post::all();
|
|
||||||
|
|
||||||
|
//HOme.php
|
||||||
|
$data = Post::all();
|
||||||
echo $data;
|
echo $data;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,9 @@ require "../../bootstrap.php";
|
||||||
use Backend\Model\Post;
|
use Backend\Model\Post;
|
||||||
|
|
||||||
if(isset($_POST['update'])){
|
if(isset($_POST['update'])){
|
||||||
$id = $_POST['id'];
|
$post = Post::query()->find($_POST['id']);
|
||||||
$title = $_POST['upTitle'];
|
$post->title = $_POST['upTitle'];
|
||||||
$description = $_POST['upDescription'];
|
$post->description = $_POST['upDescription'];
|
||||||
$post = Post::query()->find($id)->first();
|
|
||||||
$post->title = $title;
|
|
||||||
$post->description = $description;
|
|
||||||
|
|
||||||
if(!$post->update()){
|
if(!$post->update()){
|
||||||
echo "Error could not update";
|
echo "Error could not update";
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
function deletePost(id) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'get',
|
||||||
|
url: '../Backend/controller/deletePost.php',
|
||||||
|
data: {'delete_id':id},
|
||||||
|
success:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
},
|
||||||
|
error:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
$( document ).ready(function() {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: '../Backend/controller/getPost.php',
|
||||||
|
success:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
for (let i = 0; i < data.length; i++){
|
||||||
|
document.getElementById("dis").innerHTML += "<button onClick=\"deletePost(" + data[i].id + ")\">Slet opslag</button><br>";
|
||||||
|
document.getElementById("dis").innerHTML += "<a href=\"edit.php?id="+ data[i].id + "\">Edit</a> <br><hr>"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,16 @@ require "../Backend/controller/accessControl.php";
|
||||||
<title>Home</title>
|
<title>Home</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<?php $ad = $_GET['id']; ?>
|
||||||
|
|
||||||
<form action="../Backend/controller/update.php" method="POST">
|
<form action="../Backend/controller/update.php" method="POST">
|
||||||
<input type="number" name="id" hidden value="1">
|
<input type="number" name="id" hidden value="<?php echo $ad ?>">
|
||||||
<input type="text" name="upTitle" placeholder="Title">
|
<input type="text" name="upTitle" placeholder="Title">
|
||||||
<input type="text" name="upDescription" placeholder="Description">
|
<input type="text" name="upDescription" placeholder="Description">
|
||||||
<input type="submit" name="update">
|
<input type="submit" name="update">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
require "../Backend/controller/accessControl.php";
|
require "../Backend/controller/accessControl.php";
|
||||||
require "../bootstrap.php";
|
require "../bootstrap.php";
|
||||||
|
|
||||||
|
use Backend\Model\Post;
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Home</title>
|
<title>Home</title>
|
||||||
</head>
|
</head>
|
||||||
|
<style>
|
||||||
|
table {
|
||||||
|
font-family: arial, sans-serif;
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
td, th {
|
||||||
|
border: 1px solid #dddddd;
|
||||||
|
text-align: left;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:nth-child(even) {
|
||||||
|
background-color: #dddddd;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<body>
|
<body>
|
||||||
<p>Logget in som <?php echo $_SESSION['name'];?></p>
|
<p>Logget in som <?php echo $_SESSION['name'];?></p>
|
||||||
<a href="../Backend/controller/logout.php">Log ud</a>
|
<a href="../Backend/controller/logout.php">Log ud</a>
|
||||||
|
@ -19,15 +39,13 @@ require "../bootstrap.php";
|
||||||
<input type="submit" name="createPost" placeholder="Opret">
|
<input type="submit" name="createPost" placeholder="Opret">
|
||||||
</form>
|
</form>
|
||||||
<hr>
|
<hr>
|
||||||
<p>Slet post</p>
|
|
||||||
<?php
|
|
||||||
$posts = \Backend\Model\Post::all()->pluck('id');
|
<div id="dis"></div>
|
||||||
foreach ($posts as $post){
|
|
||||||
echo "<a href='../Backend/controller/deletePost.php?id=1'>Delete</a> <br>";
|
<script src="Assets/Ajax/deletePost.js"></script>
|
||||||
}
|
<script src="Assets/Ajax/fetchAndDisplayData.js"></script>
|
||||||
?>
|
|
||||||
<hr>
|
|
||||||
<p>Edit post</p>
|
|
||||||
<a href='edit.php?id=1'>Edit 1</a>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -420,6 +420,25 @@
|
||||||
dynamicMainBullets: 3,
|
dynamicMainBullets: 3,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*dasdasda*/
|
||||||
|
$( document ).ready(function() {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: '../Backend/controller/getPost.php',
|
||||||
|
success:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
},
|
||||||
|
error:function (data) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue