CakePHP Aro->save() 在用户模型中的 afterSave() 内部使用时不起作用
到目前为止,我已经尝试使这项工作大约一个小时了,我目前使用 cakephp 2,除了这段代码之外,一切都工作完美
下面是我在 User 模型中的内容
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);
}
}
基本上他做的一切都很好,用正确的 group_id 更新表 User如果我使用 debug($aro) 我可以看到它正在尝试使用正确的信息进行更新。
然而 $this->Aro->save($aro) 似乎不起作用,而且 Cake 也没有显示任何错误消息,尝试了几种调试方法但没有显示错误,它只是不更新 aro 表。
有人知道为什么会发生这种情况吗?
PS:Grupo 代替 Group,grupo_id 代替 group_id 在表格上也是正确的,它只是在这两种情况下从英语到葡萄牙语的翻译。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试打印(使用 pr($aro))来打印 $aro 数组的内容。如果它包含任何无效的字段名称(不在数据库表中的属性名称),保存操作将失败。
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.