
Question:
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
Answer1: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.
Answer2: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.