Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP响应停止已弃用_Php_Cakephp - Fatal编程技术网

CakePHP响应停止已弃用

CakePHP响应停止已弃用,php,cakephp,Php,Cakephp,我使用的是CakePHP3.5,我想使用的两种方法已经被弃用,我找不到替代方法 这些方法是: $this->response->send(); $this->response->stop(); 我想重定向到另一个页面并停止当前方法的执行。我尝试在重定向后调用die(),但它不起作用 根据调查,这些方法已经过时了 有什么想法吗 编辑: 我正在尝试重定向无法访问特定页面的用户。这在控制器中的initialize()方法中 if ($allowedAccess) {

我使用的是CakePHP3.5,我想使用的两种方法已经被弃用,我找不到替代方法

这些方法是:

$this->response->send();
$this->response->stop();
我想重定向到另一个页面并停止当前方法的执行。我尝试在重定向后调用
die()
,但它不起作用

根据调查,这些方法已经过时了

有什么想法吗

编辑:

我正在尝试重定向无法访问特定页面的用户。这在控制器中的
initialize()
方法中

if ($allowedAccess) {
    $this->Flash->error("Insufficient rights to access that location");
    $this->redirect($this->referer());
    // FIXME - find alternative to deprecated methods
    return $this->response;
    $this->response->send();
    $this->response->stop();
}

你是在控制器中尝试这个吗?只需从控制器方法返回响应对象:

public function index() {
    // Some code
    return $this->response;
}
send()只是phps的包装器。如果需要在某个地方退出,请使用exit()

当您返回响应时,将处理返回值以及它是否是响应对象。参见方法

响应将通过并最终由所使用的发送。检查您的webroot/index.php以查看它:

// Bind your application to the server.
$server = new Server(new Application(dirname(__DIR__) . '/config'));
// Run the request/response through the application
// and emit the response.
$server->emit($server->run());

这个建议对我不起作用。我在我原来的帖子中添加了更多的细节。你为什么不使用Cake附带的Auth系统呢?它将为您自动执行重定向和闪烁。阅读这一页:哦,下一次,在询问时添加所有有问题的代码。因为现在情况不同了…因为它使用LDAP并确保用户在正确的组中。LDAP可以使用cake的auth系统。至少有两个3.x插件可用,我为CakePHP 3.5+开发的新身份验证层提供了开箱即用的LDAP支持:如果您喜欢自己的实现,您应该将其作为身份验证系统的适配器来实现。我一直在使用,效果很好。但我需要能够让某些组访问某些页面,而其他组无法访问。它更像是一个“你已经登录,你可以查看任何东西”的插件,除非我在文档中遗漏了什么。我添加的功能是指定用户必须加入的组列表,以便继续,这很好,但当他们不在这些组中时,他们会尝试查看页面,我需要重新引导它们,这是不起作用的。我可以检查组,我可以验证它们是否是组的一部分,但是我能够重定向的唯一方法是使用不推荐的方法。