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

查看:59
本文介绍了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.

我知道有人建议使用会话,但这不是解决该问题的好方法.

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.

当前执行此操作的方法是:

The current way to do this would be:

在您的组件代码中:

$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天全站免登陆