Joomla - 取消设置多个会话变量不起作用 [英] Joomla - Unset multiple session variables not working

查看:21
本文介绍了Joomla - 取消设置多个会话变量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这会很简单,但我想某处有问题...我正在为 Joomla 安装开发自定义代码部分,我需要在执行我的代码之前取消设置一些会话变量.所以,很自然地,我有

I thought this would be simple but I guess there's a catch somewhere... I'm developing a custom part of code for a Joomla installation and I need to unset some session variables before executing my code. So, naturally, I have

$session->clear('var1'); 
$session->clear('var2'); 
$session->clear('var3'); 
$session->clear('var4'); 

但页面完全空白,什么也没有发生.有什么建议吗?

but the page appears totally blank and nothing happens. Any suggestions?

推荐答案

假设你有这样的 $session 变量:

Assuming that you got the $session variable like this:

$session = JFactory::getSession();

如果您得到一个空白页面,则您的代码中可能存在一些错误.您是否有权访问某种错误日志?如果不是,如果不是生产环境,您可以尝试强制显示代码中的错误(尽管这不是最好的方法)或从 joomla 管理员启用调试模式.

If you are getting a blank page, you probably some error in your code. Do you have access to some kind of error log? If not, you can try to force displaying errors from your code if it's not a production environment (although it's not the best way to do it) or enable debug mode from the joomla administrator.

您也可以尝试在浏览器中运行 php 文件,如果一切正常并且文件中没有解析错误,您应该会看到类似受限访问"或类似信息.

You can also try to run the php file in your browser, and if everything is ok and there are no parse errors in the file, you should see a message like 'Restricted access' or similar.

此外,如果脚本没有崩溃,您可以检查每次调用 $session->clear('xxx') 返回的值是什么(它应该返回您刚刚清除的值.

Besides, if the script is not crashing, you can check what value is returning each call to $session->clear( 'xxx' ) (It should return the value you just cleared.

我想到的最后一件事是您存储在会话中的变量处于不同的上下文"中.当您获取/设置会话数据时,您可以将命名空间"作为附加参数传递,因此这些变量存储在该命名空间"中(实际上,它存储在会话内的另一个索引中.因此,如果可能,您应该检查这些变量是否使用不同的命名空间"存储在会话中:

The last thing that comes to my mind is that the vars you have stored in session are in a different "context". When you get/set data to session, you can pass a "namespace" as an additional parameter, so these vars are stored in that "namespace" (in fact, it's stored inside another index inside the session. So if possible, you should check if these variables are stored in session using a different "namespace":

$session->set( 'var1', $value, 'another_namespace' );

如果是这样,你应该像这样清除它:

If so, you should clear it like this:

$session->clear( 'var1', 'another_namespace' );

PS:我说命名空间"是因为它是 Joomla 在这些会话方法中使用的参数名称,但不要与 PHP 命名空间混淆.

P.S.: I said "namespace" because it's the parameter name that Joomla uses in these session methods, but don't get confused with PHP namespaces.

希望能帮到你!

这篇关于Joomla - 取消设置多个会话变量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆