Trying to use the timehelper $this->Time->wasWithinLast($how_often, $last_updated);
But I keep getting
Error: Call to a member function wasWithinLast() on a non-object
It seems like it can't find $this->Time
? Is that correct?
$how_often
and $last_updated
are both in the correct format.
SOLUTION: Here is the solution. $this->Time only works in view. Here is how it works in model:
CakeTime::wasWithinLast($how_often, $last_updated);
This is the beginning of my reminders controller:
class RemindersController extends AppController {
/**
* Components
*
* @var array
*/
public $components = array('Paginator');
/**
* index method
*
* @return void
*/
public function index() {
var_dump($this->Time);
$this->Reminder->recursive = 0;
$this->set('reminders', $this->Paginator->paginate());
}
Here is the model:
class Reminder extends AppModel {
public function beforeSave($options = array())
{
// Attribute to this user
$this->data['Reminder']['user_id'] = AuthComponent::user('id');
$this->data['Reminder']['how_often'] = $this->data['Reminder']['number'].' '.$this->data['Reminder']['frame'];
$this->data['Reminder']['last_reminded'] = $this->data['Reminder']['created'];
}
public $virtualFields = array(
'remindable' => 'Reminder.created'
);
public function afterFind($results, $primary = false){
parent::afterFind($results, $primary);
foreach ($results as $key => $val) {
$results[$key]['Reminder']['remindable'] = $this->remindable($results[$key]['Reminder']['how_often'], $results[$key]['Reminder']['last_reminded']);
// $results[$key]['Reminder']['remindable'] = $this->Time->wasWithinLast($results[$key]['Reminder']['how_often'], $results[$key]['Reminder']['last_reminded']);
// $results[$key]['Comments']
}
// $results = Set::sort($results, '{n}.Item.score', 'desc');
return $results;
}