1
我準備了一個控制器,如下所示。用cakephp控制器返回json響應時出錯
class TasksController extends AppController
{
public function index()
{
$this->paginate = [
'contain' => ['Users'],
'conditions' => [
'Tasks.user_id' => $this->Auth->user('id'),
]
];
$tasks = $this->paginate($this->Tasks);
$this->set(compact('tasks'));
//$this->set('tasks', $this->paginate($this->Tasks));
$this->set('_serialize', ['tasks']);
}
}
和我的AppController如下。
class AppController extends Controller
{
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent("Auth", [
'authorize' => 'Controller',
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
],
'unauthorizedRedirect' => $this->referer()
]);
$this->Auth->allow(['display']);
}
}
當我輸入以下URL「http://localhost/cake/tasks.json」時,出現以下錯誤。
Error: Tasks.jsonController could not be found.
Error: Create the class Tasks.jsonController below in file: src/Controller/Tasks.jsonController.php
<?php
namespace App\Controller;
use App\Controller\AppController;
class Tasks.jsonController extends AppController
{
}
什麼是這裏的問題,以及如何解決呢無需添加路由或JSON視圖文件。 [我正在使用CakePHP 3.0]
當你進入''http:// localhost/cake/tasks'時會發生什麼 – jszobody
它顯示了web視圖中的任務列表 –
你定義了哪些路由器擴展 – drmonkeyninja