drccfl9407 2015-04-10 19:51
浏览 50
已采纳

在非对象上调用成员函数wasWithinLast()

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;
}
  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿