如何将数据保存到数据库格式的数据库中

时间:2014-08-09 11:55:46

标签: php cakephp cakephp-2.0

我有以下数组。我想在单个保存链接上将数据插入两个表。我怎么能这样做?

前三个字段将保存在产品表中,opt_vals(一个数组)将保存在另一个名为product_links的表中。

另外,我想将lastInsertId插入product_links表。 product_links字段为idproduct_idproduct_values

Array
(
    [Product] => Array
    (
        [product_name] => 
        [product_desc] => 
        [price] => 
        [opt_vals] => Array
            (
                [0] => Array
                    (
                        [id] => 
                    )

                [1] => Array
                    (
                        [id] => 
                    )

                [2] => Array
                    (
                        [id] => 
                    )

                [3] => Array
                    (
                        [id] => 
                    )

                [4] => Array
                    (
                        [id] => 
                    )

                [5] => Array
                    (
                        [id] => 
                    )

                [6] => Array
                    (
                        [id] => 
                    )

                [7] => Array
                    (
                        [id] => 
                    )
           )
    )
)

1 个答案:

答案 0 :(得分:0)

请在模型中使用模型关联$belongTo,然后才能使用

$this->Model->savAll($this->request->data);
相关问题