ブログアプリを作っています。
投稿の削除を実装しようとしているのですがうまく削除をすることができません。
DELETE処理をしようとするとこのようにエラーが出てしまいます。
調べたりしたのですがわからなかったのでわかる方がいれば教えていただきたいです。
<エラー>
Fatal error: Uncaught Error: Call to undefined method Request::get() in /home/users/2/velvet.jp-red-amami-9732/web/application/controllers/BlogController.php:182 Stack trace: #0 /home/users/2/velvet.jp-red-amami-9732/web/application/core/Controller.php(40): BlogController->deletedoneAction(Array) #1 /home/users/2/velvet.jp-red-amami-9732/web/application/core/Application.php(152): Controller->run('deletedone', Array) #2 /home/users/2/velvet.jp-red-amami-9732/web/application/core/Application.php(106): Application->runAction('blog', 'deletedone', Array) #3 /home/users/2/velvet.jp-red-amami-9732/web/application/web/index_dev.php(8): Application->run() #4 {main} thrown in /home/users/2/velvet.jp-red-amami-9732/web/application/controllers/BlogController.php on line 182
こちらがコードになります。
#Controllerfile
public function deleteAction($params) { $blog_id = $params['blog_id'];//var_dump($blog_id); $user = $this->session->get('user'); $profile = $this->db_manager->get('Profile')->getById($user['id']); $blog = $this->db_manager->get('Blog')->getBlogId($blog_id); //if(); //if(); //if(); $smarty = new Smarty(); $smarty->assign("session",$this->session); $smarty->assign("base_url",$this->request->getBaseUrl()); $smarty->assign("_content",$this->content); $smarty->assign('profile',$profile); $smarty->assign('blog',$blog); $smarty->display(VIEW_DIR . '/blog/delete.php'); } public function deletedoneAction($params) { //$blog_id = $this->request->getPost($params['blog_id']); $blog_id = $params['blog_id']; $user = $this->session->get('user'); $blog = $this->request->get('Blog')->delete($blog_id); $smarty = new Smarty(); $smarty->assign("base_url",$this->request->getBaseUrl()); $smarty->display(VIEW_DIR . '/blog/deletedone.php'); }
こちらがViewです。
#Delete file
<html lang="ja"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>投稿削除</title> <link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" /> </head> <body> <div class="confirm" style="text-align: center;"> <h1 class="confirm_content">投稿削除 内容 </h1> <form action="{$base_url}/blog/deletedone/{$blog.id}" method="post"> <input type="hidden" name="blog_id" value="" /> <p class="size">削除内容はこちらで宜しいでしょうか?<br>よろしければ「送信する」ボタンを押して下さい。</p> <div class="status"> <div class="status_content"> <img src="/uploads/{$profile.image_file}" width="60px" class="effect"/> {UtilCommon::escape($profile.nick_name)} </div> <p>{UtilCommon::escape($blog.subject)}</p> <p>{if $blog.image_file} <img src="/uploads/{$blog.image_file}" width="300px" alt="投稿画像" /> {/if} </p> <td> <p>{if 0 == $blog.category_type }{/if}</p> <p>{if 1 == $blog.category_type }#食べ物{/if}</p> <p>{if 2 == $blog.category_type }#動物{/if}</p> <p>{if 3 == $blog.category_type }#スポーツ{/if}</p> <p>{if 4 == $blog.category_type }#ファッション{/if}</p> <p>{if 5 == $blog.category_type }#娯楽{/if}</p> <p>{if 6 == $blog.category_type }#自然{/if}</p> <p>{if 7 == $blog.category_type }#その他{/if}</p> </td> <div class="create_date"> {UtilCommon::escape($blog.create_date)} </div> </div> <input type="button" value="削除しない" onclick="history.back(-1)" class="button"> <button type="submit" name="submit" class="button">削除する</button> </form> </div> </body> </html>
#Dletedone file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>会員情報フォーム</title> <link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" /> </head> <body> <div class="confirm" style="text-align: center;"> <h1 class="confirm_content">投稿削除 送信完了</h1> <div> <div> <p class="done"> 投稿削除完了しました。<br> </p> <a href="{$base_url}/account"> <button type="button" class="button">ホームに戻る</button> </a> </div> </div> </div> </body> </html>
こちらがSQLです。
<?php class BlogRepository extends DbRepository { public function insert($user_id = null,$subject = null,$category_type = null,$image_file = null) { $now = new DateTime(); $sql = "INSERT INTO blog(user_id,subject,category_type,image_file,create_date,update_date) VALUES(:user_id,:subject,:category_type,:image_file,:create_date,:update_date)"; $stmt = $this->execute($sql,array( ':user_id' => $user_id, ':subject' => $subject, ':category_type' => $category_type, ':image_file' => $image_file, ':create_date' => $now->format('Y-m-d H:i:s'), ':update_date' => $now->format('Y-m-d H:i:s'),)); return $this->con->lastInsertId(); } public function fetchAllByUserId($user_id) { $sql = "SELECT b.*,u.name FROM blog b LEFT JOIN user u ON b.user_id = u.id WHERE u.id = :id ORDER BY b.create_date DESC"; return $this->fetchAll($sql,array(':id' => $user_id)); } public function getById($user_id) { $sql = "SELECT b.*,u.name FROM blog b LEFT JOIN user u ON b.user_id = u.id WHERE u.id = :id ORDER BY b.create_date DESC"; return $this->fetch($sql,array(':id' => $user_id)); } public function getBlogId($id) { $sql = "SELECT * FROM blog WHERE id = :id"; return $this->fetch($sql,array(':id' => $id)); } public function delete($id) { $sql = "DELETE FROM blog WHERE id = :id"; return $this->execute($sql,array(':id' => $id)); }
よろしくおねがいいたします。
回答2件
あなたの回答
tips
プレビュー