cakephp saveall 错误参数 #2 不是数组

问题描述 投票:0回答:1

所以我有一段代码已经在我的本地主机和开发服务器上运行了几个月。两者都是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');
        }
    }
}

数据仍然可以很好地保存,但我如何更改它才能不引发这些错误?

php cakephp
1个回答
2
投票

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

就您而言,看起来

save($quote)

 也可以。 
save
 的第二个参数是布尔值,因此不会返回错误。

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

© www.soinside.com 2019 - 2024. All rights reserved.