【问题标题】:cakephp saveall Error Argument #2 is not an arraycakephp saveall 错误参数 #2 不是数组
【发布时间】:2014-02-18 15:39:58
【问题描述】:

所以我有一段代码已经在我的本地主机和开发服务器上运行了几个月。这两个都是windows环境。当移动到新的 linux 托管位置时,它会引发以下错误:

警告 (2):array_merge() [function.array-merge]:参数 #2 不是数组 [CORE/Cake/Model/Model.php,第 2036 行]

警告 (2):array_merge() [function.array-merge]:参数 #2 不是数组 [CORE/Cake/Model/Model.php,第 2186 行]

有问题的代码是一个 saveAll 调用,用于保存从表单中检索到的数据。有趣的是,尽管出现错误,数据仍会保存。

我的存档代码在这里

            if (!($quote['Quote']['total'] == 0 || $quote['Quote']['total'] < 0)) {
            if ($this->Quote->saveAll($quote, true)) {
                $this->Session->setFlash('Quote Saved', 'success');
                $this->redirect('/clientcases/view/' . $case . '#tab6');
            }

整个函数:

    public function makeQuote() {
    $this->loadModel('Applicant');
    $this->LoadModel('ApplicantQuote');
    $this->LoadModel('Setfee');
    $this->LoadModel('Clientcase');
    $this->LoadModel('Internalprice');
    $this->LoadModel('Clientprice');

    /* ------ retrieving client and internal prices for display ------ */
    $internal = $this->Internalprice->find('all');
    $client = $this->Clientprice->find('all');

    //retrieves the applicants chosen from the view_quotes page
    $args = $this->params['url'];
    //get the case id from the previous page

    $case = $args['data']['caseid'];
    //remove move some unnecessary things from the args array
    unset($args['data']['caseid']);
    unset($args['id']);
    //retrieve the applicant information from the database using the applicant array
    $applicants = $this->Applicant->find('all', array('conditions' => array('id' => $args['data']),
        'order' => 'first_name ASC', 'recursive' => -1));

    $app_id = Set::classicExtract($applicants, '{n}.Applicant.id');

    if ($applicants == null) {//redirect back to view quotes page if no applicants were chosen
        $this->Session->setflash('Choose at least one applicant');
        $this->redirect('/clientcases/view/' . $case . '#tab5');
    }

    $this->set(compact('applicants', 'case', 'args', 'internal', 'client'));

    if ($this->request->is('post')) {
        $cancelCheck = $_POST;
        if ($cancelCheck['QuoteButton'] == 'Cancel') {
            $this->redirect('/clientcases/view/' . $case);
        }

        $quote = $this->request->data;
        unset($quote['QuoteButton']);

        $quote["Applicant"] = array();
        $quote['Applicant']['Applicant'] = array();

        $count = 0;
        foreach ($app_id as $key => $id) {
            $quote['Applicant']['Applicant'][] = $app_id[$count];
            $count++;
        }

        $gst = 0;
        if ($quote['Quote']['includeGST'] == 1) {
            $total = $quote['Quote']['total'];

            if ($total > 0) {
                $gst = $total / 10;
            }
        }
        $quote['Quote']['GST'] = $gst;
            //debug($quote);
        unset($quote['Quote']['includeGST']);
        if (!($quote['Quote']['total'] == 0 || $quote['Quote']['total'] < 0)) {
            if ($this->Quote->saveAll($quote, true)) {
                $this->Session->setFlash('Quote Saved', 'success');
                $this->redirect('/clientcases/view/' . $case . '#tab6');
            }
        } else {
            $this->Session->setflash('Quote Failed to Save, All fields must be filled in and total greater than 0');
        }
    }
}

数据仍然保存得很好,但是我该如何更改它以使其不会引发这些错误?

【问题讨论】:

    标签: cakephp


    【解决方案1】:

    saveAll 的第二个参数是一个数组。您正在发送布尔值。

    在您的情况下,save($quote) 似乎也可以使用。 save 的第二个参数是布尔值,所以不会返回错误。

    也许警告在其他服务器上被抑制了。

    【讨论】:

    • 我不认为只是保存会起作用。表单正在尝试一次保存到 5 个不同的表格。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    • 1970-01-01
    相关资源
    最近更新 更多