I’m learning to make a simple login through codeigniter, then I got an error like
Missing argument 1 for C_login::login() when I press the “login” button on my views without entering the username and password field.
these are my controller, my IDE (netbeanPHP+CI framework) shows no error
<?php
class C_login extends CI_Controller{
public function __construct() {
parent::__construct();
$this->load->model('m_login');
}
function index()
{
$this->form_validation->set_rules('username','trim|Username','required|exact_length[4]|xss_clean');
$this->form_validation->set_rules('password','trim|Password','required|min_length[4]|max_length[40]|xss_clean|callback_login');
if($this->form_validation->run() == false)
{
$this->load->view('login');
}
else
{
echo 'sukses validasi';
}
}
function login($password)
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$jabatan = $this->input->post('jabatan');
$value = $this->m_login->cekpass($username,$password,$jabatan);
if($value)
{
return true;
}
else
{
return false;
}
}
}
?>
and here is the model, i think my model is not showing any error
<?php
class M_login extends CI_Model{
public function __construct() {
parent::__construct();
}
function login ($username, $password, $jabatan)
{
$this->db->where('username',$username);
$this->db->where('password',$password);
$this->db->where('jabatan',$jabatan);
$value = $this->db->get('ms_user');
if($value->num_rows()>0)
{
return true;
}
else
{
return false;
}
}
}?>
You need to remove the formal parameter
$passwordfrom theloginmethod of theC_logincontroller. Obviously, you’re not gonna pass the password via the URL, right?As for the second error regarding the undefined method in the model, it’s because you’re calling the method you want with the wrong name. You named it
loginin the model, yet you’re calling forcekpassin the controller. Either rename the method definition, or change what you’re calling tologininstead.