简体   繁体   中英

Codeigniter 3 'Too few arguments to function 0 exactly 1 expected'

I am a newbie in programming and get a problem with my script. I hope you can help me.

This is my problem :

An uncaught exception was encountered

Type: ArgumentCountError

Message: Too few arguments to function M_warisantb::Caridata(), 0 passed in C:\\xampp\\htdocs\\budaya\\dapobud\\application\\controllers\\Home.php on line 58 and exactly 1 expected

Filename: C:\\xampp\\htdocs\\budaya\\dapobud\\application\\models\\M_warisantb.php

Line Number: 12

Backtrace:

File: C:\\xampp\\htdocs\\budaya\\dapobud\\application\\controllers\\Home.php Line: 58 Function: Caridata

File: C:\\xampp\\htdocs\\budaya\\dapobud\\index.php Line: 315 Function: require_once

I'm trying to make a search with select query (in Codeigniter 3) I start to build a form to start the search like this :

 <form method="POST" action="<?php echo base_url('Home/Cari');?>" class="d-none d-sm-inline-block form-inline mr-auto ml-md-3 my-2 my-md-0 mw-100 navbar-search"> <div class="input-group"> <input name="cari" type="text" class="form-control bg-light border-0 small" placeholder="Search for..." aria-label="cari" aria-describedby="basic-addon2"> <div class="input-group-append"> <button class="btn btn-primary" type="submit"> <i class="fas fa-search fa-sm"></i> </button> </div> </div> </form>

and I create model to run this function like this :

public function Caridata($cari)
{
    $this->db->like('domain_opk', $cari);
    return $this->db->get_where('tradisi')->result_array();
}

in my opinion $cari come from <input name="cari" type="text">

This is my controller

public function Cari()
{
    $data['title'] ='Galeri Foto';  
    $data['tradisi'] = $this->M_warisantb->Caridata();
    $this->load->view('templates/header',$data);
    $this->load->view('templates/sidebar');
    $this->load->view('templates/topbargaleri');
    $this->load->view('templates/galeri',$data);
    $this->load->view('templates/footer');
}

Thanks in advance for your help...

In model you have created a function Caridata which is parameterized and as you mentioned that parameter is from your form so, first fetch the input value from form and then pass it to the function when you are calling it in controller. Simply as below -

$name = $this->input->post('cari');

Then, instead of -

$data['tradisi'] = $this->M_warisantb->Caridata();

Do this -

$data['tradisi'] = $this->M_warisantb->Caridata($name);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM