using JParameter in Joomla

 ̄綄美尐妖づ 提交于 2020-01-07 06:15:45

问题


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);

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


回答1:


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.




回答2:


You could do it with a content Plugin which gets trigerred on view.

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

Good thing about that method is you don't need any core hacks.



来源:https://stackoverflow.com/questions/8070213/using-jparameter-in-joomla

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!