Skip to content

Commit 9d3b2b1

Browse files
committed
remove get_post function
1 parent c3c268d commit 9d3b2b1

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

controller.php

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ public function view($id){
8989
$this->initSilder();
9090
$this->render('post.html');
9191
}
92+
public function delete($id, $router){
93+
(new Post())->find(intval($id))->delete();
94+
$router->error(302, '/posts');
95+
}
9296
public function create($router, $user_id, $category_id, $category, $title, $content, $tag){
9397
if ($user_id){
9498
if ($category){

index.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
})
3636
->error(405, function($message){
3737
header("Location: /posts", true, 302);
38-
die('aaa');
38+
die('405');
3939
})
4040
->delete('/uninstall', function($router){
4141
@unlink('blog.db');
@@ -68,12 +68,7 @@
6868
->get('/posts', array(new PostController(), 'listall'))
6969
->get('/post/create', array(new PostController(), 'create'), 'auth')
7070
->post('/post/create', array(new PostController(), 'create'), 'auth')
71-
->get('/post/:id/delete', function($id, $router){
72-
$post = get_post($id);
73-
$post->updateTag('');
74-
$post->delete();
75-
$router->error(302, '/posts');
76-
}, 'auth')
71+
->get('/post/:id/delete', array(new PostController(), 'delete'), 'auth')
7772
->get('/post/:id/edit', array(new PostController, 'edit'), 'auth')
7873
->post('/post/:id/edit', array(new PostController, 'edit'), 'auth')
7974
->get('/post/:id/view', array(new PostController, 'view'))

model.php

-6
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,4 @@ class Post2Tag extends ActiveRecord{
104104
);
105105
}
106106

107-
function get_post($id=null){
108-
return (new Post())->eq('id', (int)($id?$id:1))->find();
109-
}
110-
function get_user($id=null){
111-
return (new User())->eq('id', (int)($id?$id:1))->find();
112-
}
113107

test/BlogTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public function testPosts(){
8181
public function testPostDelete($postId){
8282
$response = $this->getRequest()->get('http://127.0.0.1:8889/post/'. $postId. '/delete');
8383
$this->assertEquals(302, $response->getHttpCode());
84-
$this->assertEquals(302, $response->getHttpCode());
8584
$this->assertEmpty($response->getContent());
8685
$this->assertEquals('/posts', $response->getHeader()->getLocation());
8786
}

0 commit comments

Comments
 (0)