-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.php
More file actions
87 lines (78 loc) · 2.8 KB
/
routes.php
File metadata and controls
87 lines (78 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
//DBとの接続
include('dbconnect.php');
//urlを分解し変数へ
$params = explode('/',$_GET['url']);
//1つ目の要素を$resourseに
$resource = $params[0];
//自作関数を使い、複数形にも対応させる
$plural_resource = singular2plural($resource);
//2つ目の要素を$actionに定義
$action = $params[1];
//さらにoptionが指定される場合は3つ目の要素をidとして定義
if (count($params) > 2) {
$id = $params[2];
}
//includeでmodel,controller,viewを呼び出さす
//modelの呼び出し
include('models/'.$resource.'.php');
//contorollerの呼び出し
include('controllers/'.$plural_resource.'_controller.php');
include('./views/layouts/application.php');
include('./views/layouts/function.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)) {
$plural = $dictionary[$singular];
} elseif (preg_match('/(a|i|u|e|o)o$/', $singular)) {
$plural = $singular . "s";
} elseif (preg_match('/(s|x|sh|ch|o)$/', $singular)) {
$plural = preg_replace('/(s|x|sh|ch|o)$/', '$1es', $singular);
} elseif (preg_match('/(b|c|d|f|g|h|j|k|l|m|n|p|q|r|s|t|v|w|x|y|z)y$/', $singular)) {
$plural = preg_replace('/(b|c|d|f|g|h|j|k|l|m|n|p|q|r|s|t|v|w|x|y|z)y$/', '$1ies', $singular);
} elseif (preg_match('/(f|fe)$/', $singular)) {
$plural = preg_replace('/(f|fe)$/', 'ves', $singular);
} else {
$plural = $singular . "s";
}
return $plural;
}
?>