我正在使用数据库进行会话处理。对于使用 RequestHandler 的一些 web 服务调用,我想停止为这些控制器的某些特定操作创建自动会话
我的问题:如何在控制器的某些操作中停止自动会话启动?请注意,我在 AppController 中定义了 Auth 组件。有什么方法可以停止会话吗?我需要在行动中使用 $this->Session->destroy() 吗?
澄清
在每个 web 服务调用上,它都会在数据库中创建一个新的会话行。但我没有在 action.ie 中使用任何会话功能。即如果有人调用 10 次操作,它会创建 10 个会话。我觉得它会创建数据库空间和时间开销。
按照建议应用新更改
使用它无法获得正确的结果
// overwrite constructClasses() for remove session in certain actions
public function constructClasses() {
// remove the Session from components again here
// either globally or for certain actions
if (in_array($this->action, array('test1','test2'))) {
foreach($this->components as $key => $val){
if($val =='Session'){
unset($this->components[$key]);
}
}
}
parent::constructClasses();
}
但是 API 调用在 test1 0r test2 上创建了新的会话 ID
// out put of below code.
function beforeFilter() {
pr($this->components);
}
大批 ( [饼干] => [认证] => 数组 ( [登录操作] => 数组 ( [控制器] => 资源 [动作] => 登录 )[loginRedirect] => Array ( [controller] => resources [action] => view ) [logoutRedirect] => Array ( [controller] => resources [action] => login ) [authenticate] => Array ( ...... ) ) [Security] => Array ( [csrfExpires] => +1 hour ) [RequestHandler] =>
)