v0.1.2 - Added edit function
fixed create function Deleted old update
This commit is contained in:
@@ -5,7 +5,10 @@ use Backend\Model\Post;
|
||||
|
||||
header('Content-Type: application/json;charset=UTF-8');
|
||||
|
||||
$data = Post::all();
|
||||
if(isset($_POST['id']))
|
||||
$data = Post::find($_POST['id']);
|
||||
else
|
||||
$data = Post::all();
|
||||
echo $data;
|
||||
|
||||
|
||||
|
||||
@@ -4,14 +4,12 @@ require "../../bootstrap.php";
|
||||
|
||||
use Backend\Model\Post;
|
||||
|
||||
if(isset($_POST['update'])){
|
||||
if(isset($_POST['id'])){
|
||||
$post = Post::query()->find($_POST['id']);
|
||||
$post->title = $_POST['upTitle'];
|
||||
$post->description = $_POST['upDescription'];
|
||||
|
||||
if(!$post->update()){
|
||||
echo "Error could not update";
|
||||
}else{
|
||||
header("location: ../../Frontend/admin.php");
|
||||
if($post->update()){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,6 @@ if(isset($_POST['title'])){
|
||||
$post->description = $_POST['description'];
|
||||
|
||||
//Call the save function.
|
||||
if(!$post->save()){
|
||||
return http_response_code(400);
|
||||
}else{
|
||||
echo $post->id;
|
||||
}
|
||||
if($post->save())
|
||||
echo json_encode(array($post->id, $post->created_at));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user