Naufal Ghifari
Naufal Ghifari

Reputation: 1

An uncaught Exception was encountered: Call to undefined method codeigniter

Please help me. I've tried to solve it, but what is the problem in my code? This is my first time to encounter this error. I really need help, please.

This is the error I'm getting:

Message: Call to undefined method M_data::cek_login() in C:\xampp\htdocs\perpustakaan\application\controllers\Login.php Line Number: 32

here is my controllers :

<?php 
defined('BASEPATH') or exit('No direct script access allowed');
class Login extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }  
    public function index()
    {
        $this->load->view('v_login');
    }
   
    public function login_aksi()
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $sebagai = $this->input->post('sebagai');

        $this->form_validation->set_rules('username', 'Username', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');

        if ($this->form_validation->run() != false) {
            $where = array(
                'username' => $username,
                'password' => md5($password)
            );

            if ($sebagai == "admin") {
                $cek = $this->m_data->cek_login('admin', $where)->num_rows();
                $data = $this->m_data->cek_login('admin', $where)->row();
                if ($cek > 0) {
                    $data_session = array(
                        'id' => $data->id,
                        'username' => $data->username,
                        'status' => 'admin_login'
                    );
                    $this->session->set_userdata($data_session);
                    redirect(base_url() . 'admin');
                } else {
                    redirect(base_url() . 'login?alert=gagal');
                }
            } else if ($sebagai == "petugas") {
                $cek = $this->m_data->cek_login('petugas', $where)->num_rows();
                $data = $this->m_data->cek_login('petugas', $where)->row();
                if ($cek > 0) {
                    $data_session = array(
                        'id' => $data->id,
                        'nama' => $data->nama,
                        'username' => $data->username,
                        'status' => 'petugas_login'
                    );
                    $this->session->set_userdata($data_session);
                    redirect(base_url() . 'petugas');
                } else {
                    redirect(base_url() . 'login?alert=gagal');
                }
            }
        } else {
            $this->load->view('v_login');
        }
    }
}

My Models :

<?php

class M_data extends CI_Model
{

    function get_data($table)
    {
        return $this->db->get($table);
    }

    function insert_data($data, $table)
    {
        $this->db->insert($table, $data);
    }

    function edit_data($where, $table)
    {
        return $this->db->get_where($table, $where);
    }

    function update_data($where, $data, $table)
    {
        $this->db->where($where);
        $this->db->update($table, $data);
    }

    function delete_data($where, $table)
    {
        $this->db->delete($table, $where);
    }
}

Upvotes: 0

Views: 4242

Answers (1)

Ilham Syahru Ramadhan
Ilham Syahru Ramadhan

Reputation: 153

it's because you don't have any function called cek_login() inside M_data.

you should define it like :

function cek_login($table, $where)
{
    //put your script here
}

Upvotes: 1

Related Questions