Joomla pass value from component to use in plugin and module(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 从组件传递值以在插件和模块中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Joomla 从组件传递值以在插件和模块中使用
- Laravel 仓库 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
