Cakephp 无法更新 shell 文件中的数据

Cakephp can't update data in shell file

下面的 shell 脚本应该在发送电子邮件通知后更新 Notification.emailed 数据库单元格,但它不起作用。我尝试了保存方法和保存字段方法,但它们不起作用。我从控制台调用了 shell 并且没有错误,并且 $id 和 $email 按照脚本的最后两行显示在屏幕上。我无法调试,因为没有错误。请帮忙

这是我的 shell 脚本的一部分:

<?php
App::uses('CakeEmail', 'Network/Email');

class EmailnotificationShell extends AppShell {

public $uses = array('User', 'Notification');

public function fsnotify() {

    $notifications = $this->Notification->find('all', array(
    'recursive' => 1,
    'conditions' => array('Notification.viewed' => '0', 'Notification.emailed' => '0', 'User.emailauth' => '1'),
    'group' => array('Notification.user_id')
    ));

    foreach ($notifications as $notification){

    $email = $notification['User']['email'];
    $id = $notification['Notification']['id'];

      $this->Notification->id = $id;
      // $this->Notification->saveField('emailed', 1, array('validate' => false, 'callbacks' => false));

      $data = array('Notification.emailed' => 1);
      $this->Notification->save($data);
      $this->Notification->clear();
     // below lines for testing in console
      $this->out($id);
      $this->out($email);
    }

}

您不应该在保存数据数组中使用别名作为列名的前缀。所以如下:-

$data = array('Notification.emailed' => 1);
$this->Notification->save($data);

应该是:-

$data = array('emailed' => 1);
$this->Notification->save($data);

如果仍未保存,请尝试检查是否存在任何验证错误:-

debug($this->Notification->invalidFields());

没有明显的错误并不意味着没有办法调试您的代码! :-)