質問編集履歴

1

コード追加

2016/05/05 14:10

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,13 +1,181 @@
1
- 現在オブジェクト指向でリアルタイムチャットを開発中なのですが、どこにajaxを組み込めばいいのかわかりません。
1
+ 現在オブジェクト指向(mvcモデル)でリアルタイムチャットを開発中なのですが、どこにjavascriptを組み込めばいいのかわかりません。
2
2
 
3
3
 
4
4
 
5
+ /chatin/loginだった場合下のコードのChatinControllerクラスのloginActionメソッドを実行されるように
6
+
5
7
  URLでルーティング
6
8
 
7
- (/chat/login だった場合chatクラスのloginメソッドを実行)
9
+ loginAction()内の
8
10
 
9
- することにより処理を実行しているのですが、javascriptはどこに組み込んでいけばいいのでしょうか?
11
+ return $this->render($variables = array('_token' => $this->generateToken('aoiin/login') ,);
12
+
13
+ でビューファイル(HTML)と必要な値を出力
10
14
 
11
15
 
12
16
 
17
+ $connection = $this->property['db_info']->getDbClass('Member');
18
+
19
+ でmodelクラスに接続し処理結果を取得。
20
+
21
+
22
+
23
+ return $this->property['response']->setHeader('Location' , 'http:');
24
+
25
+ で chat/welcome にリダイレクト。
26
+
27
+
28
+
29
+ ChatControllerクラスのwelcomeActionメソッドを実行し
30
+
31
+ チャット画面を表示
32
+
33
+
34
+
35
+ のようにしてmvcモデルでチャットを開発しているのですが、ここにajaxを組み込めばいいのかわかりません。
36
+
37
+ ajaxで接続するPHPファイルは手続き型で書いて適当な場所においてmvcモデルとは別にするべきでしょうか。
38
+
39
+
40
+
41
+
42
+
13
- わかりづらくてすみませんがお願いします
43
+ 自分なりに作成したフレームワーク(?)で開発している為わかりづらくてすみませんがお願いします
44
+
45
+
46
+
47
+ ```PHP
48
+
49
+ class ChatinController extends Controller
50
+
51
+ {
52
+
53
+ public function loginAction()
54
+
55
+ {
56
+
57
+ try {
58
+
59
+ if ($this->property['validate']->issetVal(array('name',) , 'post') !== false) {//nameが入力されている時
60
+
61
+ $name = $this->property['request']->getPost(array('name'));
62
+
63
+ $token = $this->property['request']->getPost(array('_token',));
64
+
65
+ $connection = $this->property['db_info']->getDbClass('Member');
66
+
67
+ $count = $connection->countUserName($name['name']);
68
+
69
+ if($count == 0 && $connection->countUser() <= 13
70
+
71
+ &&$this->checkToken('aoiin/login' , $token['_token']) !== false){//ユーザー名の重複、入室ユーザ13人以下
72
+
73
+ $connection->insertUserName($name['name']);
74
+
75
+ $this->property['session']->setSession(array('name' => $name['name']));
76
+
77
+ $this->property['session']->setSession(array('time' => time()));
78
+
79
+ $user_name = $this->property['session']->getSession('name');
80
+
81
+
82
+
83
+ return $this->property['response']->setHeader('Location' , 'http:');
84
+
85
+ }elseif($count !== 0) {//ユーザ名重複
86
+
87
+ throw new Exception('This username has been used .');
88
+
89
+ }elseif ($connection->countUser() > 13) {//満室
90
+
91
+ throw new Exception('Full house');
92
+
93
+ }
94
+
95
+ }elseif($this->property['validate']->issetVal(array('name',) , 'session') !== false){
96
+
97
+ return $this->property['response']->setHeader('Location' , 'http:');
98
+
99
+ }
100
+
101
+ }catch (Exception $e) {
102
+
103
+ return $this->render($variables = array('_token' => $this->generateToken('aoiin/login') , '_error' => $e->getMessage() ,) , $layout = 'aoilayout');
104
+
105
+ }
106
+
107
+ return $this->render($variables = array('_token' => $this->generateToken('aoiin/login') ,) , $layout = 'aoilayout');
108
+
109
+ }
110
+
111
+
112
+
113
+ public function logoutAction()
114
+
115
+ {
116
+
117
+ $connection_out = $this->property['db_info']->getDbClass('Out');
118
+
119
+ $connection_mem = $this->property['db_info']->getDbClass('Member');
120
+
121
+ if ($connection_out->getLastOutId() >= 6) {
122
+
123
+ $connection_out->deleteOutUser();
124
+
125
+ }
126
+
127
+ $name = $this->property['session']->getSession('name');
128
+
129
+ $connection_out->insertOutUser($name);
130
+
131
+ $connection_mem->deleteUser($name);
132
+
133
+ $this->property['session']->removeSession(array('name',));
134
+
135
+ return $this->property['response']->setHeader('Location' , 'http:');
136
+
137
+ }
138
+
139
+ }
140
+
141
+
142
+
143
+ ```
144
+
145
+
146
+
147
+ ```PHP
148
+
149
+ class ChatController extends Controller
150
+
151
+ {
152
+
153
+ public function welcomeAction()
154
+
155
+ {
156
+
157
+ if ($this->property['validate']->issetVal(array('name',) , 'session')) {
158
+
159
+ $user_name = $this->property['session']->getSession('name');
160
+
161
+ $this->property['session']->setSession(array('time' => time()));
162
+
163
+
164
+
165
+ return $this->render($variables = array('user' => $user_name , ) , $layout = 'aoilayout');
166
+
167
+ }elseif ($this->property['session']->getSession('time')+3600 > time()
168
+
169
+ || $this->property['validate']->issetVal(array('name',) , 'session') !==false) {
170
+
171
+
172
+
173
+ return $this->property['response']->setHeader('Location' , 'http://');
174
+
175
+ }
176
+
177
+ }
178
+
179
+ }
180
+
181
+ ```