Home > Back-end >  codeigniter 3 'Too few arguments to function 0 exactly 1 expected'
codeigniter 3 'Too few arguments to function 0 exactly 1 expected'

Time:09-26

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

this 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 search with select query (in codeigniter 3) i start to build 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 before for your helping....

CodePudding user response:

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);
  • Related