Error Loading Model in Codeigniter

Asked

Viewed 1,050 times

1

Hello,

I’m trying to carry the model inside my controller as follows:

$this->load->model("gerente");

But simply everything after this code does not work, I tried to load by passing "Manager" instead of "manager" but the only difference is that this way appears "Error 500".

Here’s the Model code I’m trying to call:

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

class Gerente extends Usuario {
    public function __construct() {
        parent::__construct();
    }
}

/* End of file gerente.php  */
/* Location: ./application/models/gerente.php */

User is a class that is calling CI_MODEL. And I’m already carrying the database $this->load->database();

  • Uploaded the database to autoload? $this->load->database(); $this->load->model("gerente"); What’s in that one required? I usually assemble a class and extend it.

  • Yeah, I uploaded the database to autoload. Sorry, I forgot to comment on extend, I am used in CI_MODEL in the user.php file, and even if I call only $this->load->model('user'), no error appears, only nothing after that code works, like 'manager''

1 answer

1

Your.php manager file should extend the class CI_Model of Codeigniter to then load the parent constructor of that class.

//gerente.php Model
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
    //require_once 'usuario.php';

    class Gerente extends CI_Model {
        public function __construct() {
            parent::__construct();
        }
        //TODO here
    }

//home.php Controller
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');     
    class Home extends CI_Controller {
        public function __construct() {
            parent::__construct();
            $this->load->model('gerente'); // ou no autoload do config.php ou em cada método.
        }
        //TODO here
    }
  • 1

    Sorry, I forgot to comment about extend, I am used in CI_MODEL in the user.php file, and even if I call only $this->load->model('user'), no error appears, only nothing after that code works, same 'manager''

  • Include error_reporting(E_ALL) at the beginning to show warnings and class errors. Include some prints to debug the model execution, because in theory it should work!

  • Man, very curious, I’m using the url /user/ register to call the controller, I added an echo before calling the model and an after, what ta before prints, but the most curious thing is that I opened the browser’s Network tab and is giving error 500 for /user/

  • There must be something missing within your users.php model or there is something else that completes the execution. Include prints throughout the functions or in the constructor. Where not to print should be an error!

  • Hey, man, thanks a lot! In addition to calling $this->load->database() in various places, which is probably not the right one, I commented my role insert in the user model and worked correctly, just missing I find out what was doing wrong in the function, but this is another story... Thanks! hehe

Browser other questions tagged

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