###CakePHP3にて
該当コントローラーのアクション内にて$this->autoRender = false; を指定すると、viewファイルによる描画だけでなくecho "test"の内容も表示されません。
どなたかご教授お願い致します。
問題解決のためにできる限りシンプルな内容で作成しました。
以下、行ったことの一覧です。
- 「php composer.phar create-project --prefer-dist cakephp/app testapp」コマンドにて新しいプロジェクトを作成。
- mysql上に'testapp'データベースを作成。
- app.confのDatasources部を修正。
- 手書きにてTestsController.phpを作成。
- 表示を確認。
以下該当コードです。
php
<?php 'Datasources' => [ 'default' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', /** * CakePHP will use the default DB port based on the driver selected * MySQL on MAMP uses port 8889, MAMP users will want to uncomment * the following line and set the port accordingly */ //'port' => 'non_standard_port_number', 'username' => 'testapp', 'password' => 'testapp', 'database' => 'testapp', 'encoding' => 'utf8', 'timezone' => 'UTC', 'flags' => [], 'cacheMetadata' => true, 'log' => false, /** * Set identifier quoting to true if you are using reserved words or * special characters in your table or column names. Enabling this * setting will result in queries built using the Query Builder having * identifiers quoted when creating SQL. It should be noted that this * decreases performance because each query needs to be traversed and * manipulated before being executed. */ 'quoteIdentifiers' => false, /** * During development, if using MySQL < 5.6, uncommenting the * following line could boost the speed at which schema metadata is * fetched from the database. It can also be set directly with the * mysql configuration directive 'innodb_stats_on_metadata = 0' * which is the recommended value in production environments */ //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'], 'url' => env('DATABASE_URL', null), ],
php
<?php namespace App\Controller; use App\Controller\AppController; class TestsController extends AppController { public function index() { $this->autoRender = false; echo "test"; } }
よろしくお願い致します。
追記:
ご提示いただいたコードを参考にコードを作成しましたが、ブラウザよりアクセスすると「Controller actions can only return Cake\Network\Response or null.」というメッセージが表示され、
ajax経由でアクセスすると「500 (Internal Server Error)」というメッセージが帰ってきます。
ご教授お願い致します。
php
<?php namespace App\Controller; use App\Controller\AppController; class TestsController extends AppController { public function index() { $this->autoRender = false; $returnData = array('test'=>'test'); return json_encode($returnData); } }
まだ回答がついていません
会員登録して回答してみよう