Error accessing Model Codeigniter

0

I've checked and all my calls are correct. The code ran on Windows and transferred it to Ubuntu. After the download gives this error:

  

An Error Was Encountered

     

Unable to locate the model you have specified: crudmodel

The model in question (crudModel.php):

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

class CrudModel extends CI_Model {

    public function __construct()
    {       
        parent::__construct();
    }

    public function add($tabela= NULL, $dados= NULL){
        if ($this->db->insert($tabela, $dados)){
            return TRUE;
        }
        else{
            return FALSE;
        }
    }

    public function delete($tabela= NULL, $dados= NULL){
        $this->db->where('id', $dados);
        if ($this->db->delete($tabela)){
            return TRUE;
        }
        else return FALSE;  
    }

    public function read($tabela= NULL){

        $result= $this->db->get($tabela);
        return $result;     
    }

    public function buscaDados($tabela= NULL, $dados= NULL){

        if ($tabela!= NULL && $dados!= NULL){
            $this->db->where('id', $dados);
            if ($this->db->update($tabela)){
                return TRUE;
            }
            else return FALSE;  
        }
        else return FALSE;  
    }

    public function update($tabela= NULL, $dados= NULL){

        if ($tabela!= NULL && $dados!= NULL){
            return $result= $this->db->get_where($tabela, $dados);
        }
        else return FALSE;      
    }
}

From what I've seen, the problem is in autoload ... but I do not know how to hit that.

Autoload:

$autoload['packages'] = array();
$autoload['libraries'] = array('form_validation', 'session', 'database', 'table', );
$autoload['helper'] = array('url', 'form', 'html', 'file', );
$autoload['model'] = array('crudModel', 'sessionModel', );

Example of calling the method of the model class:

$dados= $this->crudModel->buscaDados('usuario',$dados);
    
asked by anonymous 06.02.2014 / 13:56

2 answers

4

Just like you already had this problem. I resolved by passing the file name to lowercase. I use the first letter of the class name in uppercase, but this does not interfere with loading the class.

Example:

Filename: usuario_model ;

Class name: Usuario_model ;

This is related to the fact that the Codeigniter class CI_Loader passes the name of the class to be loaded to lowercase before loading. So when trying to load a model you can either declare:

$this->load->model('usuario_model'); 

Or

$this->load->model('Usuario_model');

Since the name of the file in which the class is contained is lowercase, you should have no problem.

But the use of the class strictly obeys the syntax used to load it. Example:

If you use:

$this->load->model('Usuario_model');

When you use it you should use:

$this->Usuario_model->get_by_id($id);

If you use:

$this->load->model('usuario_model');

When you use it you should use:

$this->usuario_model->get_by_id($id);
    
06.02.2014 / 18:11
4

According to this topic , just leave the file at lowercase

TheFuzzy0ne :

  

If nothing has changed then only difference will be the operating   system (one Linux and one Windows). Windows is case insensitive,   whereas Linux is not, so you need to ensure that the filenames for   your models are ALL lowercase, and that the name is defined in   all lowercase (as it is with the file), but has the first letter   capitalised. Hopefully this will solve the problem.

translation

  

If nothing has changed, then only difference will be the operating system (a   Linux and a Windows). Windows is case insensitive, while Linux   it is not, so it is necessary to make sure that file names   for your models have lowercase letters, and that the name of the   class is set to all lowercase letters (as it is with the   file), but has the first letter uppercase. Hopefully this will   solve the problem.

    
06.02.2014 / 15:36