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

时间:2015-05-28 14:30:52

标签: php shell cakephp

下面的shell脚本应该在发送电子邮件通知后更新Notification.emailed数据库单元但它不起作用。我已经尝试了save方法和saveField方法,但它们无法正常工作。我从控制台调用了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);
    }

}

1 个答案:

答案 0 :(得分:0)

您不应该使用保存数据数组中的别名为列名添加前缀。以下是: -

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

应该是: -

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

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

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

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