dongliang1654 2011-08-30 19:56
浏览 41

在用户模型中的afterSave()内使用时,CakePHP Aro-> save()不起作用

Have been trying to make this work for about an hour so far, im currently using cakephp 2 and everything is working perfect except this code

Here follows what I have inside User model

var $actsAs = array('Acl' => array('type' => 'requester'));

public function bindNode($user)
{
    # ativando o simplified node mode
    # trabalharemos apenas com permissões referentes ao grupo e não a cada usuário
    #
    return array('model' => 'Grupo', 'foreign_key' => $user['User']['grupo_id']);
}

public function parentNode()    # utilizado para determinar um relacionmamento Pai -> Filho
{
    if (!$this->id && empty($this->data))
        return null;

    if (isset($this->data['User']['grupo_id']))
        $groupId = $this->data['User']['grupo_id'];
    else
        $groupId = $this->field('grupo_id');

    if (!$groupId)
        return null;
    else
        return array('Grupo' => array('id' => $groupId));
}

public function afterSave( $created )   # depois que as infos deste usuario sao salvas
{
    # Funcao para permitir atualizar os grupos dos usuarios
    if (!$created)
    {
        $parent = $this->parentNode();
        $parent = $this->node($parent);
        $node = $this->node();
        $aro = $node[0];
        $aro['Aro']['parent_id'] = $parent[0]['Aro']['id'];
        $this->Aro->save($aro);
    }
}

Basicaly he do everything just fine, update the table User with the correct group_id and if I use debug($aro) I can see it is trying to update with the correct information.

However the $this->Aro->save($aro) doens´t seem to work, also Cake dont show any error msg whatsoever, tryed several ways of debugging but no error is shown, it simply doesnt update the aro table.

ANyone have any idea why this is hapenning?

PS.: the Grupo instead of Group and grupo_id instead of group_id is also correct on the tables, its just a translation from English to Portuguese on those 2 cases only.

  • 写回答

1条回答 默认 最新

  • doushi4956 2011-11-20 22:39
    关注

    Try printing (using pr($aro)) to print the contents of the $aro array. If it contains any invalid field names (names of attributes not in the database table) the saving operation will fail.

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端