質問編集履歴
3
修正結果の確認でエラー、調査中。
title
CHANGED
File without changes
|
body
CHANGED
@@ -165,7 +165,19 @@
|
|
165
165
|
|
166
166
|
ーー追記ーー
|
167
167
|
|
168
|
+
以下より
|
168
169
|
|
170
|
+
修正を試したところ「+=」演算子がの所でエラーになってしまいました
|
171
|
+
バージョンの問題かと思ったんですが、以下該当の行のエラーですが、
|
172
|
+
|
173
|
+
Notice (8): Object of class Cake\ORM\Query could not be converted to int [APP/Controller\UserController.php, line 27]
|
174
|
+
|
175
|
+
> $user["units"] += $units;
|
176
|
+
|
177
|
+
ここで int に変換しようとしているようで、どちらも連想配列だと思うのですが。
|
178
|
+
違うのでしょうか。
|
179
|
+
|
180
|
+
■
|
169
181
|
修正したコード
|
170
182
|
|
171
183
|
```php
|
@@ -182,6 +194,7 @@
|
|
182
194
|
echo json_encode($user);
|
183
195
|
```
|
184
196
|
|
197
|
+
■
|
185
198
|
「Unsupported operand types」が発生しています。
|
186
199
|
```
|
187
200
|
Notice (8): Object of class Cake\ORM\Query could not be converted to int [APP/Controller\UserController.php, line 27]
|
@@ -194,7 +207,7 @@
|
|
194
207
|
Error
|
195
208
|
```
|
196
209
|
|
197
|
-
|
210
|
+
■
|
198
211
|
バージョン確認してみました。
|
199
212
|
PHP Version 7.2.34
|
200
213
|
CakePHP
|
2
バージョンや、修正コードの結果を追記です
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
CakePHPです。
|
2
|
+
PHP Version 7.2.34(localhostにアクセスして頭に表示されている)
|
3
|
+
|
2
4
|
目的は、モデルから取り出したデータをjsonにしてかえそうとしています。
|
3
5
|
|
4
6
|
DBを個別に取り出しているのは、まだ間もないためModelの操作が分からないためです。
|
@@ -158,4 +160,61 @@
|
|
158
160
|
],
|
159
161
|
[]
|
160
162
|
]
|
163
|
+
```
|
164
|
+
|
165
|
+
|
166
|
+
ーー追記ーー
|
167
|
+
|
168
|
+
|
169
|
+
修正したコード
|
170
|
+
|
171
|
+
```php
|
172
|
+
$id = 1;
|
173
|
+
$query = TableRegistry::get('userdata');
|
174
|
+
$user = $query->find()->where(['id' => $id])->first();
|
175
|
+
$query_useritem = TableRegistry::get('useritem');
|
176
|
+
$items = $query_useritem->find()->where(['user_id' => $id]);
|
177
|
+
$query_userunit = TableRegistry::get('userunit');
|
178
|
+
$units = $query_userunit->find()->where(['user_id' => $id]);
|
179
|
+
|
180
|
+
$user["units"] += $units;
|
181
|
+
$user["items"] += $items;
|
182
|
+
echo json_encode($user);
|
183
|
+
```
|
184
|
+
|
185
|
+
「Unsupported operand types」が発生しています。
|
186
|
+
```
|
187
|
+
Notice (8): Object of class Cake\ORM\Query could not be converted to int [APP/Controller\UserController.php, line 27]
|
188
|
+
Notice (8): Object of class Cake\ORM\Query could not be converted to int [APP/Controller\UserController.php, line 28]{"id":1,"name":"test_user","rank":1,"exp":0,"lastlogin":"2021-12-04T18:11:24+00:00","created":"2021-12-04T18:11:24+00:00","units":1,"items":1}
|
189
|
+
Warning (512): Unable to emit headers. Headers sent in file=D:\_TechStadium20211101\ts\90_FinalProject\20_ServerProject\htdocs\PriconneR\vendor\cakephp\cakephp\src\Error\Debugger.php line=853 [CORE\src\Http\ResponseEmitter.php, line 48]
|
190
|
+
Warning (2): Cannot modify header information - headers already sent by (output started at D:\_TechStadium20211101\ts\90_FinalProject\20_ServerProject\htdocs\PriconneR\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 148]
|
191
|
+
Warning (2): Cannot modify header information - headers already sent by (output started at D:\_TechStadium20211101\ts\90_FinalProject\20_ServerProject\htdocs\PriconneR\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 181]
|
192
|
+
Warning (2): Cannot modify header information - headers already sent by (output started at D:\_TechStadium20211101\ts\90_FinalProject\20_ServerProject\htdocs\PriconneR\vendor\cakephp\cakephp\src\Error\Debugger.php:853) [CORE\src\Http\ResponseEmitter.php, line 181]
|
193
|
+
Unsupported operand types
|
194
|
+
Error
|
195
|
+
```
|
196
|
+
|
197
|
+
|
198
|
+
バージョン確認してみました。
|
199
|
+
PHP Version 7.2.34
|
200
|
+
CakePHP
|
201
|
+
```
|
202
|
+
$ php bin/cake
|
203
|
+
################################################################################
|
204
|
+
#
|
205
|
+
# Cake is a shell script for invoking CakePHP shell commands
|
206
|
+
#
|
207
|
+
# CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
208
|
+
# Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
209
|
+
#
|
210
|
+
# Licensed under The MIT License
|
211
|
+
# For full copyright and license information, please see the LICENSE.txt
|
212
|
+
# Redistributions of files must retain the above copyright notice.
|
213
|
+
#
|
214
|
+
# @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
215
|
+
# @link https://cakephp.org CakePHP(tm) Project
|
216
|
+
# @since 1.2.0
|
217
|
+
# @license https://opensource.org/licenses/mit-license.php MIT License
|
218
|
+
#
|
219
|
+
################################################################################
|
161
220
|
```
|
1
タイトル変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
[PHP] 連想配列をjson形式に変換する時
|
1
|
+
[PHP] 連想配列をjson形式に変換する時の事ですが、形式を入れ子にする方法が分かりませんでした。連想配列を入れ子にするのだと思いましたがみつからずです。
|
body
CHANGED
File without changes
|