PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 6, 2022

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

 January 06, 2022     codeigniter, php     No comments   

Issue

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...


Solution

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


Answered By - P N Jain
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing