Hi everyone! I need some help with a module that saves sum of integer fields as a hidden field value. There are 3 integer fields in template: rating1, rating2, rating3 and one hidden field: total. Can't figure out, how to save the field value to DB... I tried use $field->set and $fields->save, but all what i get is Call to a member function save() on a non-object error.
<?php
class TotalRating extends WireData implements Module {
/**
* @return array
*/
public static function getModuleInfo() {
return array(
'title' => 'Total rating',
'version' => 100,
'summary' => '',
'singular' => true,
'autoload' => true,
);
}
public function init() {
$this->pages->addHookAfter('save', $this, 'total');
}
public function total($event) {
$page = $event->arguments[0];
if ($page->template == "cat") {
$rat1 = $page->rating1;
$rat2 = $page->rating2;
$rat3 = $page->rating3;
$ratTotal = $rat1 + $rat2 + $rat3;
//save $ratTotal as "total" field value
}
}
}