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 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c