【问题标题】:Error: An uncaught Exception was encountered错误:遇到未捕获的异常
【发布时间】:2020-05-30 07:00:36
【问题描述】:

我收到此错误:

遇到未捕获的异常类型:ArgumentCountError

消息:函数的参数太少 Home::cadastroOrcamentoCliente(), 0 传入 C:\xampp\htdocs\sistema_financas_old\system\core\CodeIgniter.php 第 532 行,正好是 6 行

文件名: C:\xampp\htdocs\sistema_financas_old\application\controllers\Home.php

行号:1116

回溯:

文件:C:\xampp\htdocs\sistema_financas_old\index.php 行:315 函数:require_once

这是我的代码:

//Inicio de desenvolvimento new window client.
    //New Página para gerar pedido de cliente.
    function cadastroOrcamentoCliente($cpfcnpj=null, $tipo_pessoa=null, $dados = null, $id_pf, $id_cliente, $id_cadastro) {
        $tipo_login = $this->session->userdata('tipo_login');
        if ($tipo_login == '1' || $tipo_login == '4' || $tipo_login == '5') {
            $dadosPessoa['tipo_pessoa'] = null;
            $dadosOrcamento['str'] = $this->load->view('admin/compras/popup_cadastro', $dadosPessoa, true);
            if ($tipo_pessoa == 1) {
                $dadosOrcamento['cpf'] = $cpfcnpj;
                $dadosOrcamento['cnpj'] = null; 
            } else if ($tipo_pessoa == 2) {
                $dadosOrcamento['cpf'] = null;
                $dadosOrcamento['cnpj'] = $cpfcnpj;
            } else {
                $dadosOrcamento['cpf'] = $cpfcnpj;
                $dadosOrcamento['cnpj'] = $cpfcnpj; 
            }

            if ($this->alteracao->editEndereco($id_cadastro) && $this->alteracao->editPessoaFisica($id_pf) &&
                $this->alteracao->editCliente($id_cliente) && $this->alteracao->editCadastroComum($id_cadastro) && $this->alteracao->editarDadosBancarios($id_cadastro)) {
            $data_cad = date("d/m/Y");
            $hora_cad = date("H:i:s");
            $this->alteracao->cadastroHistorico('Dados do cliente editados', $id_cadastro, $data_cad, $hora_cad);
            $this->alteracao->mensagemAlerta("Dados alterados com sucesso!", 1, "home/cadastros", $id_cadastro);

            $dadosOrcamento['orcamento'] = $this->compras_m->buscarOrcamentoAtual($this->session->userdata('id_orcamento'));
            $this->load->view('admin/head');
            $dadosBarra['dadosB'] = $this->financeiro->listaContas();
            $this->load->view('admin/barraSuperior', $dadosBarra);
            $dadosLogo['logo'] = $this->adm->retornaLogo();
            $this->load->view('admin/menu', $dadosLogo);
            $this->load->view('admin/vendas/cadastro_orcamento_cliente', $dadosOrcamento);
            $this->load->view('admin/footer');
        } else {
            $dados['mensagem'] = null;
            $this->paginas($dados);
        }
    }
    }

我在这里打电话

 <form method="post" action="<?php echo site_url('pedido/cadastroOrcamentoVendaCliente') ?>">

只需创建一个新屏幕并需要项目的其他内容

【问题讨论】:

  • 告诉我们你如何称呼cadastroOrcamentoCliente()
  • 只需创建一个新屏幕,需要对项目进行补充
  • 你还没有显示对该函数的调用

标签: php codeigniter


【解决方案1】:

这个:

function cadastroOrcamentoCliente($cpfcnpj=null, $tipo_pessoa=null, $dados = null, $id_pf,
                                  $id_cliente, $id_cadastro)

从根本上说是错误的。

https://www.php.net/manual/en/functions.arguments.php#functions.arguments.default:

请注意,使用默认参数时,任何默认值都应位于任何非默认参数的右侧;否则,事情将无法按预期进行。

您需要在此处更改参数的顺序 - 没有默认值的需要排在第一位,而只有在其之后的:

function cadastroOrcamentoCliente($id_pf, $id_cliente, $id_cadastro, $cpfcnpj=null,
                                  $tipo_pessoa=null, $dados = null)

然后您仍然必须在实际调用该函数时至少为其中的前三个提供值。

【讨论】:

    【解决方案2】:

    如果您将字段发布到cadastroOrcamentoCliente,则不应定义参数计数。 POST 字段不被视为函数参数,这就是您收到错误的原因(您声明该函数必须准确接收 6 个参数,但它没有收到)

    只需将函数声明为function cadastroOrcamentoCliente(),然后通过$this-&gt;input-&gt;post('fieldname') 处理发布的字段(在使用表单验证助手验证所有内容之后)

    【讨论】:

      猜你喜欢
      • 2023-01-28
      • 1970-01-01
      • 2019-04-03
      • 1970-01-01
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      相关资源
      最近更新 更多