$resource = $params[0]; $action = $params[1]; if (count($params) > 2) { $id = $params[2]; } // リソース名を複数形に変換する処理 $plural_resource = singular2plural($resource); // model呼び出す include './models/' . $resource . '.php'; include './models/category.php'; // controller呼び出す include './controllers/' . $plural_resource . '_controller.php'; // リソース名がdeleteなら削除処理する if ($action == 'delete') { $BlogsController = new BlogsController($db, $plural_resource); $BlogsController->delete($id); } // viewの形成を楽にするヘルパーファイルを読み込み include './views/helpers/application_helper.php'; // レイアウトファイルを読み込み include './views/layouts/application.php'; // ./ ← 現在いるディレクトリ ?> <?php // 単数形resource名の単語を複数形に変換する関数 function singular2plural($singular) { $dictionary = array('man' => 'men', 'seaman' => 'seamen', 'snowman' => 'snowmen', 'woman' => 'women', 'person' => 'people', 'child' => 'children', 'foot' => 'feet', 'crux' => 'cruces', 'oasis' => 'oases', 'phenomenon' => 'phenomena', 'tooth' => 'teeth', 'goose' => 'geese', 'genus' => 'genera', 'graffito' => 'graffiti', 'mythos' => 'mythoi', 'numen' => 'numina', 'equipment' => 'equipment', 'information' => 'information', 'rice' => 'rice', 'money' => 'money', 'species' => 'species', 'series' => 'series', 'fish' => 'fish', 'sheep' => 'sheep', 'swiss' => 'swiss', 'chief' => 'chiefs', 'cliff' => 'cliffs', 'proof' => 'proofs', 'reef' => 'reefs', 'relief' => 'reliefs', 'roof' => 'roofs', 'piano' => 'pianos', 'photo' => 'photos', 'safe' => 'safes'); if (array_key_exists($singular, $dictionary)) {
$controller->show($id); break; case 'add': $controller->add(); break; case 'create': $controller->create($post['title'], $post['body']); break; case 'edit': $controller->edit($id); break; case 'update': $controller->update($id, $post['title'], $post['body']); break; case 'delete': $controller->delete($id); break; default: break; } class BlogsController { //プロパティ private $action = ''; private $resource = ''; private $viewOptions = ''; private $id = ''; private $title = ''; private $body = ''; public function index() {
<?php // BlogsControllerのshowを呼び出す $BlogsController = new BlogsController($db, $plural_resorce, $option); $blogs = $BlogsController->delete();