Joomla 从组件传递值以在插件和模块中使用 [英] Joomla pass value from component to use in plugin and module

查看:15
本文介绍了Joomla 从组件传递值以在插件和模块中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从组件传递一个值或在某个页面上设置某个值,然后它可以在 joomla 的插件或模块中使用?

How can I pass a value from component or set the certain value on a certain page that it then could be use in the plugin or module of joomla?

例如,在此视图中:index.php?option=com_mycom&view=myview 将设置 $a = 1(它可以从数据库生成).

For example, in this view: index.php?option=com_mycom&view=myview will set $a = 1 (it could be generated from database).

每次人们来到这个地址时,都会有一个变量$a = 1,我可以在我的插件中使用它.

Every time people come to this address there will be a variable $a = 1 that I could use it in my plugin.

我知道有些人建议使用 session,但这对我来说不是解决这个问题的好方法.

I know some people suggest using session but it is not a good way for me to solve this problem.

推荐答案

老问题,我知道,但这里没有答案,事情从上面的原始评论略有变化.JRequest 现在已在 Joomla 的最新版本中弃用.

Old question, I know, but there are no answers here, and things have moved on slightly from the original comment above. JRequest is now deprecated in recent versions of Joomla.

目前的做法是:

在您的组件代码中:

$app = JFactory::getApplication();
$app->input->set('myvar', 123);

在您的模块/插件代码中:

In your module/plugin code:

$app = JFactory::getApplication();
$app->input->get('myvar');

如您所说,使用会话对象是实现此目的的另一种方法,但它的明显缺点是在 Web 请求之间持久化,这通常不是您想要的.

As you say, using the session object is another way to do this, but it has the obvious downside of being persisted between web requests, which is often not what you want.

这篇关于Joomla 从组件传递值以在插件和模块中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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