質問するログイン新規登録

質問編集履歴

2

新たなコードの追加

2016/09/01 10:07

投稿

Babyloos
Babyloos

スコア8

title CHANGED
File without changes
body CHANGED
@@ -74,4 +74,26 @@
74
74
 
75
75
  ```
76
76
 
77
- よろしくお願い致します。
77
+ よろしくお願い致します。
78
+
79
+ 追記:
80
+ ご提示いただいたコードを参考にコードを作成しましたが、ブラウザよりアクセスすると「Controller actions can only return Cake\Network\Response or null.」というメッセージが表示され、
81
+ ajax経由でアクセスすると「500 (Internal Server Error)」というメッセージが帰ってきます。
82
+
83
+ ご教授お願い致します。
84
+
85
+ ```php
86
+ <?php
87
+ namespace App\Controller;
88
+
89
+ use App\Controller\AppController;
90
+
91
+ class TestsController extends AppController
92
+ {
93
+ public function index() {
94
+ $this->autoRender = false;
95
+ $returnData = array('test'=>'test');
96
+ return json_encode($returnData);
97
+ }
98
+ }
99
+ ```

1

詳細情報の追記

2016/09/01 10:07

投稿

Babyloos
Babyloos

スコア8

title CHANGED
@@ -1,1 +1,1 @@
1
- CakePHP3の$this->autoRender = false; につ
1
+ CakePHP3の$this->autoRender = false; を指定すると何も表示されな
body CHANGED
@@ -1,13 +1,77 @@
1
1
  ###CakePHP3にて
2
- 下記コーようにController内の該当アクションにて$this->autoRender = false; を指定echoでメッセージを表示させうとしていすが、エラー何も表示されなくなってしいます
2
+ 該当ントロラーのアクションにて$this->autoRender = false; を指定するとviewファイルによる描画だけなくecho "test"の内容も表示されません
3
+ どなたかご教授お願い致します。
3
4
 
5
+ 問題解決のためにできる限りシンプルな内容で作成しました。
6
+ 以下、行ったことの一覧です。
7
+ 1. 「php composer.phar create-project --prefer-dist cakephp/app testapp」コマンドにて新しいプロジェクトを作成。
8
+ 2. mysql上に'testapp'データベースを作成。
9
+ 3. app.confのDatasources部を修正。
10
+ 4. 手書きにてTestsController.phpを作成。
11
+ 5. 表示を確認。
12
+
13
+ 以下該当コードです。
14
+
15
+ ```php
16
+ <?php
17
+ 'Datasources' => [
18
+ 'default' => [
19
+ 'className' => 'Cake\Database\Connection',
20
+ 'driver' => 'Cake\Database\Driver\Mysql',
21
+ 'persistent' => false,
22
+ 'host' => 'localhost',
23
+ /**
24
+ * CakePHP will use the default DB port based on the driver selected
25
+ * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
26
+ * the following line and set the port accordingly
27
+ */
28
+ //'port' => 'non_standard_port_number',
29
+ 'username' => 'testapp',
30
+ 'password' => 'testapp',
31
+ 'database' => 'testapp',
32
+ 'encoding' => 'utf8',
33
+ 'timezone' => 'UTC',
34
+ 'flags' => [],
35
+ 'cacheMetadata' => true,
36
+ 'log' => false,
37
+
38
+ /**
39
+ * Set identifier quoting to true if you are using reserved words or
40
+ * special characters in your table or column names. Enabling this
41
+ * setting will result in queries built using the Query Builder having
42
+ * identifiers quoted when creating SQL. It should be noted that this
43
+ * decreases performance because each query needs to be traversed and
44
+ * manipulated before being executed.
45
+ */
46
+ 'quoteIdentifiers' => false,
47
+
48
+ /**
49
+ * During development, if using MySQL < 5.6, uncommenting the
50
+ * following line could boost the speed at which schema metadata is
51
+ * fetched from the database. It can also be set directly with the
52
+ * mysql configuration directive 'innodb_stats_on_metadata = 0'
53
+ * which is the recommended value in production environments
54
+ */
55
+ //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
56
+
57
+ 'url' => env('DATABASE_URL', null),
58
+ ],
4
59
  ```
60
+
61
+ ```php
62
+ <?php
63
+ namespace App\Controller;
64
+
65
+ use App\Controller\AppController;
66
+
67
+ class TestsController extends AppController
68
+ {
5
- public function index() {
69
+ public function index() {
6
- $this->autoRender = false;
70
+ $this->autoRender = false;
7
- echo "test";
71
+ echo "test";
72
+ }
8
73
  }
74
+
9
75
  ```
10
76
 
11
- なお、$this->autoRender = false; をコメントアウトすると通常通りMissing Templateのエラーページが表示されます。
12
-
13
- どなたかご教授お願い致します。
77
+ よろしくお願い致します。