当前位置: 首页 > 知识库问答 >
问题:

遇到未捕获的异常类型:ArgumentCountError消息:参数太少,无法使用函数Cats100::sale(),已传递0

慎兴业
2023-03-14

单击视图上的“销售”按钮后出现错误

错误:

遇到未捕获的异常

类型:ArgumentCountError

消息:太少的参数功能猫100::销售(),0传递在C:\xampp\htdocs\catshop 100\system\core\CodeIgniter.php在第532行,正好1预期

文件名:C:\xampp\htdocs\catshop100\application\controllers\Cats100。php

电话号码:61

回溯:

文件:C:\xampp\htdocs\catshop100\index。php

电话号码:315

功能:require_once

控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cats100 extends CI_Controller {
  
  public function __construct(){
    parent::__construct();
    $this->load->library('session');
    $this->load->helper('url');
    $this->load->model('CatsModel100');
    $this->load->model('CateModel100');
  }
  
  public function index(){
    $data['cats100'] = $this->CatsModel100->view();
    $this->load->view('kucing/index_cats_100', $data);
  }
  
  public function tambah(){
    if($this->input->post('submit')){
      if($this->CatsModel100->validation("save")){ 
        $this->CatsModel100->save();
        if($this->db->affected_rows() > 0){
          $this->session->set_flashdata('msg','Cat Successfuly Added');
        }else{
            $this->session->set_flashdata('msg','Cat Add Failed');
        }
        redirect('cats100');
      }
    }
    $data['category']=$this->CateModel100->view();
    $this->load->view('kucing/form_tambah_cats_100', $data);
  }
  
  public function ubah($id){
    if($this->input->post('submit')){
      if($this->CatsModel100->validation("update")){ 
        $this->CatsModel100->edit($id);
        if($this->db->affected_rows() > 0){
          $this->session->set_flashdata('msg','Cat Successfuly Edited');
        }else{
            $this->session->set_flashdata('msg','Cat Edit Failed');
        }
        redirect('cats100');
      }
    }
    $data['category']=$this->CateModel100->view();
    $data['cats100'] = $this->CatsModel100->view_by($id);
    $this->load->view('kucing/form_ubah_cats_100', $data);
  }
  
  public function hapus($id){
    $this->CatsModel100->delete($id);
    if($this->db->affected_rows() > 0){
      $this->session->set_flashdata('msg','Cat Successfuly Deleted');
    }else{
        $this->session->set_flashdata('msg','Cat Delete Failed');
    }
    redirect('cats100');
  }

  public function sale($id){
    if($this->input->post('submit')){
            $this->CatModel100->sale($id);
            if($this->db->affected_rows() > 0){
                $this->session->set_flashdata('msg','<p  style="color:black">Cat Succesfully Sold!</p>');
            }else{
                $this->session->set_flashdata('msg','<p  style="color:red">Cat Sale Failed!</p>');
            }
            redirect('cats100');
        }
    $data['cats100'] = $this->CatsModel100->view_by($id);
    $this->load->view('kucing/cat_sale_100', $data);
  }
}

型号:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class CatsModel100 extends CI_Model {

  public function view(){
    return $this->db->get('cats100')->result();
  }

  public function view_by($id){
    $this->db->where('id_100', $id);
    return $this->db->get('cats100')->row();
  }

  public function validation($mode){
    $this->load->library('form_validation'); 
    
    if($mode == "save")
        $this->form_validation->set_rules('input_id', 'ID', 'required|numeric|max_length[10]');
        $this->form_validation->set_rules('input_name', 'Nama', 'required');
        $this->form_validation->set_rules('input_type', 'Type', 'required');
        $this->form_validation->set_rules('input_gender', 'Gender', 'required');
        $this->form_validation->set_rules('input_age', 'Age', 'required');
        $this->form_validation->set_rules('input_price', 'Price', 'required');
      
    if($this->form_validation->run()) 
      return TRUE; 
    else 
      return FALSE; 
  }
  
  public function save(){
    $data = array(
      "id_100" => $this->input->post('input_id'),
      "name_100" => $this->input->post('input_name'),
      "type_100" => $this->input->post('input_type'),
      "gender_100" => $this->input->post('input_gender'),
      "age_100" => $this->input->post('input_age'),
      "price_100" => $this->input->post('input_price')
    );
    $this->db->insert('cats100', $data); 
  }
  
  public function edit($id){
    $data = array(
        "name_100" => $this->input->post('input_name'),
        "type_100" => $this->input->post('input_type'),
        "gender_100" => $this->input->post('input_gender'),
        "age_100" => $this->input->post('input_age'),
        "price_100" => $this->input->post('input_price')
    );
    
    $this->db->where('id_100', $id);
    $this->db->update('cats100', $data); 
  }
  
  public function delete($id){
    $this->db->where('id_100', $id);
    $this->db->delete('cats100');
  }

  public function sale($id){
    $data = array(
      "customer_name_100" => $this->input->post('customer_name_100'),
      "customer_address_100" => $this->input->post('customer_address_100'),
      "customer_phone_100" => $this->input->post('customer_phone_100'),
      "cat_id_100" => $id
    );
    $this->db->insert('catsales100', $data); 
    $this->db->set('sold_100', '1');
    $this->db->where('id_100', $id);
    $this->db->update('cats100', $sold); 
  }
}

视图:

<html>
  <head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
    <title>Form Cat Sale - CATSHOP100</title>
  </head>
    <body style="background-color:aquamarine;">
    <nav class="navbar navbar-expand-md bg-dark navbar-dark fixed-top">
        <a href="<?=base_url();?>" class="navbar-brand">Catshop100</a>
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
              <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="collapsibleNavbar">
              <ul class="navbar-nav">
                  <li class="nav-item">
                      <a href="<?=site_url('cats100')?>" class="nav-link">Manage Cats</a>
                  </li>
                  <li class="nav-item">
                    <a href="<?=site_url('cat100')?>" class="nav-link">Manage Categories</a>
                  </li>
                  <li class="nav-item">
                    <a href="<?=site_url('user100')?>" class="nav-link">Manage Users</a>
                  </li>
              </ul>
          </div>
    </nav>
    <br><br><br><br>
    <?php echo form_open("cats100/sale"); ?>
    <div class="container bg-dark text-white" style="width:50%;">
        <h2>Form Cat Sales</h2>
        <div class="form-group">
            <label for="cat id">Cat ID</label>
            : <?php echo set_value('input_id', $cats100->id_100); ?>
        </div>
        <div class="form-group">
            <label for="cat name">Cat Name</label>
            : <?php echo set_value('input_name', $cats100->name_100); ?>
        </div>
        <div class="form-group">
            <label for="cat type">Cat Type</label>
            : <?php echo set_value('input_price', $cats100->type_100); ?>
        </div>
        <div class="form-group">
            <label for="cat price">Cat Price</label>
            : $.<?php echo set_value('input_price', $cats100->price_100); ?>
        </div>
        <div class="form-group">
            <label for="customer name">Customer Name</label>
            <input type="text" name="customer_name_100" class="form-control">
        </div>
        <div class="form-group">
            <label for="customer address">Customer Address</label>
            <textarea name="customer_address_100" id="" class="form-control"></textarea>
        </div>
        <div class="form-group">
            <label for="customer phone">Customer Phone</label>
            <input type="text" name="customer_phone_100" class="form-control">
        </div>
        <div class="form-group">
            <input type="submit" name="submit" value="Sale" class="btn btn-success">
            <a href="<?=site_url('cats100')?>"><input type="button" value="Batal" class="btn btn-danger"></a>
        </div>
    </div>
    </body>
<html>

请帮我解决这个问题

共有1个答案

罗光华
2023-03-14

代码

 类似资料: