0

I have setup my Codeigniter inside the a sub-folder of my live website eg. www.example.com/project/ci. When i am trying to load model inside my controller i am getting error of Unable to locate the model you have specified. I have changed the $config['base_url'] to /project/ci inside application > config > config.php.

The template files which we place inside views folder of application folder is working fine but the model is not loading. I have a model of Login inside application > models > admin > Login.php.

Here is the code of my controller where i am calling model.

<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Home extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library('session');
        $this->load->helper('form');
        $this->load->helper('url');
        $this->load->helper('html');
        $this->load->database();
    }
    public function admin_login()
    {
            $this->load->model('admin/Login');
            $result = $this->Login->get_user_details();
            print_r($result);
    }
}

Here is the code of my model:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Model
{
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();

    }
    //get the username & password
    function get_user_details()
    {
        echo "coming";
    }
}
?>

I am calling function admin_login with ajax from a view. Here is my script code calling function admin_login.

 var ajaxURL = "<?php echo base_url();?>admin/Home/admin_login/"; //url of controller
 jQuery.post(ajaxURL, function(data)
 {
     alert(data);
 });

This code is working fine on xamp. Can anyone help me where i am wrong.

Developer
  • 43
  • 1
  • 8

2 Answers2

0

I found the fix. The is issue was the file name. The model was not loading because the file name was Login.php. So I changed File name from Login.php to login.php and it starts working.

Developer
  • 43
  • 1
  • 8
0

Codeigniter always concern about file name and its usage. During the creation of a file name of any controller and model, you should use Capital Form. Sometimes it doesn't create problems in local server. But it creates problems in Linux server online.

Another important you should know that, you will always match file name and class name.

You can see below code as an example

models
Studentmodel.php
Clientmodel.php


Controllers
Studentcontroller.php
ClientController.php

Ariful Islam
  • 696
  • 6
  • 11