如何在 cakephp 3.6.10 中使用 $this->autoRender = false?

How to use $this->autoRender = false in cakephp 3.6.10?

我试图通过 运行 pagesController 中的函数 test() 在屏幕上显示测试数据。使用 $this->autoRender = false ,但它仍然给我错误:

请帮帮我。我认为存在一些版本问题,但我无法弄清楚。谢谢。

Cakephp默认将Pages controller的显示动作作为主页。 display 函数本身管理页面和子页面,这就是您出错的原因。您可以在 /config/routes.php

中更改默认主页
 $routes->connect('/', ['controller' => 'Pages', 'action' => 'index']);

在其他控制器中定义您的测试操作。

从显示操作中删除代码

class PagesController {
    function display()
    {
        // default controller code here
        // your custom code here
    }
}

希望这会奏效。