CakePHP:保存关联数据

标签 cakephp

我正在尝试保存属于 IssueHistory 的 IssueHistoryDe​​scription。 所以IssueHistory有很多IssueHistoryDe​​scription。这一切都已在模型中设置。

但是,当我将其保存在 IssueHistory 中时,使用 $IssueHistory->save($data);

(在...之前有或没有$IssueHistory->create();)

Array
(
    [IssueHistory] => Array
        (
            [id] => 22
        )

    [IssueHistoryDescription] => Array
        (
            [old_description] => OLD
            [description] => NEW
        )

)

它不起作用,没有保存任何内容。

当我尝试使用 saveAssociated() 时,出现错误:

fatal error :无法在第 2248 行/var/www/xdev/kipdomanager/cakephp/lib/Cake/Model/Model.php 中使用字符串偏移量作为数组

最佳答案

你可以试试这个:

$data = array(
    'IssueHistory' => array('id' => 2),
    'IssueHistoryDescription' => array(
        array('old_description' => 'OLD', 'description' => 'new')
    )
);

$IssueHistory->create();
$IssueHistory->saveAll( $data );

关于CakePHP:保存关联数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12307640/

相关文章:

php - 在 CakePHP 中,如何计算来自联合操作的匹配项?

php - api cakephp 休息认证

php - CakePHP 导入的 Controller 作用域问题

php - 为什么将框架文件夹放在公共(public)根目录之外更安全?

php - 有没有办法让 saveAll() 删除无关的对象?

cakephp - 如何扩展或覆盖 CakePHP Core Helper 的功能/方法

javascript - Cakephp 复选框 CSS 不工作

mysql - cakephp 3.0 将两列中的值作为一列获取

CakePHP - CakeDC 插件权限不起作用

php - CakePHP 发送带有链接的查询