fix post crud
This commit is contained in:
@ -30,7 +30,7 @@ class PostController extends Controller
|
||||
$postForm = new CreatePostForm();
|
||||
$postService = new PostService();
|
||||
$postForm->load($_REQUEST);
|
||||
if((new UserService)->check($_REQUEST['username'])) {
|
||||
if((new UserService)->check($_REQUEST['user_id'])) {
|
||||
if ($postForm->validate()) {
|
||||
$post = $postService->create($postForm);
|
||||
if ($post) {
|
||||
@ -47,9 +47,9 @@ class PostController extends Controller
|
||||
|
||||
public function actionIndex(): void
|
||||
{
|
||||
$posts = Post::all();
|
||||
$contents = Post::all();
|
||||
|
||||
$this->cgView->render("post/index.php", ['posts' => $posts]);
|
||||
$this->cgView->render("post/index.php", ['contents' => $contents]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,12 +57,12 @@ class PostController extends Controller
|
||||
*/
|
||||
public function actionView($id): void
|
||||
{
|
||||
$post = Post::find($id);
|
||||
$content = Post::find($id);
|
||||
|
||||
if (!$post){
|
||||
if (!$content){
|
||||
throw new Exception(message: "The post not found");
|
||||
}
|
||||
$this->cgView->render("post/view.php", ['post' => $post]);
|
||||
$this->cgView->render("post/view.php", ['content' => $content]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,16 +78,19 @@ class PostController extends Controller
|
||||
$this->cgView->render("post/form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
$post = Post::find($id);
|
||||
if (!$post){
|
||||
throw new Exception(message: "The user not found");
|
||||
throw new Exception(message: "The post not found");
|
||||
}
|
||||
$postForm = new CreatePostForm();
|
||||
$postService = new PostService();
|
||||
$postForm->load($_REQUEST);
|
||||
if((new UserService)->check($_REQUEST['username'])) {
|
||||
if((new UserService)->check($_REQUEST['user_id'])) {
|
||||
if ($postForm->validate()) {
|
||||
$post = $postService->update($postForm, $post);
|
||||
if ($post) {
|
||||
|
Reference in New Issue
Block a user