在Joomla中使用JParameter [英] using JParameter in Joomla

查看:87
本文介绍了在Joomla中使用JParameter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用JParams存储a的最后一次访问日期 Joomla 1.7.1网站中的特定页面.所以在代码中,我正在做类似的事情:

I'm thinking of using JParams to store the last visited date of a certain page in a Joomla 1.7.1 site. So in the code I'm doing something like:

$last_run       = $params->get('last_visit', '2000-01-01');
// set last_run to current run time
$params->set('last_visit', $now);

问题显然是为last_visit重新设置的值 尽管已设置,但没有存储.

The problem is obviously that the newly set value for last_visit doesn't get stored, though it does get set.

是否有某种方法可以存储参数,而无需通过数据库 询问?谢谢

Is there some way to store the params, without going through a DB query? Thanks

推荐答案

以下是您的问题的示例解决方案,但请记住,这是针对Joomla 1.5的

Here's an example solution of your problem, but bare in mind this is for 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();

如果您不想更改组件的核心,那么所有这些操作都可以在插件中完成,否则,如果您正在构建的是组件,则可以在组件的模型"中进行设置,然后从控制器上调用每次保存.

All this could be done in a plugin if you don't want to alter the core of the component otherwise if it's a component the you are building you can set this in the Model of the component and call it from the controller on every save.

这篇关于在Joomla中使用JParameter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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