Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Joomla中使用JParameter_Php_Joomla - Fatal编程技术网

Php 在Joomla中使用JParameter

Php 在Joomla中使用JParameter,php,joomla,Php,Joomla,我正在考虑使用JParams来存储 Joomla 1.7.1站点中的某些页面。因此,在代码中,我做了如下操作: $last_run = $params->get('last_visit', '2000-01-01'); // set last_run to current run time $params->set('last_visit', $now); 问题显然是上次访问的新设置值 不会被存储,但会被设置 有没有办法存储参数,而不必经过数据库 查询谢谢您可以使用一个

我正在考虑使用JParams来存储 Joomla 1.7.1站点中的某些页面。因此,在代码中,我做了如下操作:

$last_run       = $params->get('last_visit', '2000-01-01');
// set last_run to current run time
$params->set('last_visit', $now);
问题显然是上次访问的新设置值 不会被存储,但会被设置

有没有办法存储参数,而不必经过数据库
查询谢谢

您可以使用一个在查看时触发的内容插件

public function onContentPrepare(...) {
   ...store hit date into table...
}

这种方法的好处是,您不需要任何核心攻击。

这里有一个解决问题的示例,但请记住,这是针对Joomla 1.5的

// Get instance of the table object of your component
$table =& JTable::getInstance( 'mytable');
// Set the item, this could be Article ID for example
$table->load($id);
// Load the parameters through JParameter
$params   = new JParameter($table->params);
$params->set($key,$value);
$table->params = $params->toString();
// Save to database
$table->store();

如果你不想改变组件的核心,所有这些都可以在插件中完成,否则如果它是你正在构建的组件,你可以在组件模型中设置它,并在每次保存时从控制器调用它。

那是Joomla的哪个版本?1.5或1.6+1.7.1-对不起,应该说得更清楚。好的。我还有一个问题,页面是指文章还是菜单项?谢谢Mike——但我不想把值保存到DB,因为各种原因——我想存储一个实际的参数。我明白了,但即使这样,也不要破解核心并使用插件是明智的。如果你不打算做一个插件,你可以为项目页面创建一个内容覆盖,并从那里存储新的参数(不再有黑客攻击)
components\com\u content\views\article\tmpl\default.php
ok,但问题是“如何存储参数”?我希望会有某种Jparam::store()函数来实现这一点。请看infinity的答案。@infinity--谢谢你的提示,但同样,这只是为一个表设置参数,而不是为组件在Joomla extensions表(Joomla 1.5x中的jos_组件)中注册的参数,对吗?根据Joomla核心团队的说法,没有办法做我认为可能的事情(例如,使用Jparameter::store()类型的函数)。你需要基本上按照上面@infinity所说的去做。