Model Codeigniter Access Error

Asked

Viewed 587 times

0

I already checked and all my calls are correct. The code ran on Windows and transferred it to Ubuntu. After the transfer 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 the autoload... but I don’t know how to hit it.

Autoload:

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

Call example of model class method:

$dados= $this->crudModel->buscaDados('usuario',$dados);
  • 2

    Son, we need data, codes to analyze before we can give an answer. I don’t know about the others, but I missed the divination chairs in college (although my clients also ignore that!). = D

  • I wonder if there is any reason that might cause this error... something related to the core of codeigniter, if you needed code analysis posted the same in the question.

  • Dude, path! It was in windows, and you switched to Linux. Inclusion of real path, bars (windows uses \ , already linux uses /)... as I said, there are many possibilities. Post the codes, from inclusion to standard paths. It is more accurate to help you.

  • Information is really lacking

  • @Away, edit your question and ask the IC version.

  • Put the autoload, mah! Put it where you include it. Everything, so we know what it is!

  • @Away the class name shouldn’t be Crudmodel instead of crudModel ?

  • The class name is Crudmodel, following the rule of having the first letter of the upper class name, now the file name and its calls have the first letter in Lower.

Show 3 more comments

2 answers

4


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

Example:

File name: 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 both declare:

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

Or

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

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

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

Use:

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

When using it you must use it:

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

Use:

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

When using it you must use it:

$this->usuario_model->get_by_id($id);
  • I changed the names to Ower and solved the problem. Thank you

4

According to this topical, just leave the file in 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 class name is defined in all lowercase (as it is with the file), but has the first Letter capitalised. Hopefully this will resolve the problem.

translating

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

  • I checked my names and they’re all right, both in class names and file names.

  • 1

    @Away: according to the information provided, it is not enough to check - it has to alter. The file name needs to be all lower case. The class name has to be all lower case - except the first letter. Example: file crudmodel.php for the class class Crudmodel.

  • 1

    In the documentation, It says: 'Class names must have the first letter uppercase with the rest of the name lowercase. Make sure your class extends the Model base class.'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.