ZF2 会话和重定向仅适用于本地服务器



早上好!

我在本地服务器上用 ZF2 开发了一个系统,但在迁移到 Web 服务器时,我注意到了一些奇怪的事情。我还在第三台服务器上进行了测试,谜团仍在继续。在错误日志中,不显示任何内容。会话不起作用,数据根本不持久化。我还注意到重定向不起作用。我正在使用Apache和PHP 7.1

会话代码:

$this->session = new Container('search');
if( !empty($this->params()->fromPost('search')) ){
    $this->session->offsetSet('search', $this->params()->fromPost('search') );
}
return $this->getResponse()->setStatusCode(200)->setContent(Json::encode(
    $this->session->offsetGet('search')
));

重定向代码:

if( !$logged ){
    $this->redirect()->toRoute("login", array(
        'controller' => 'login',
        'action' => 'index'
    ));
}
我认为

,您应该在调用重定向插件时使用 return 语句。

return $this->redirect()->toRoute("login", array(
        'controller' => 'login',
        'action' => 'index'
    ));

它应该有帮助。

最新更新