Sneaksta
Sneaksta

Reputation: 1061

HMVC Module Error - Undefined property: model

So I'm getting the error: Undefined property: badge_progress::$bp_model.

I don't understand what's going on. Here is my code:

Controller:

<?php
// Badge Progress Module

class badge_progress extends CI_Controller 
{
    function __construct()
    {
        parent::__construct();

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

        $data['dotpoints'] = $this->bp_model->dotpoints('1');
        $this->load->view('bp_view', $data);
    }
}

?>

Model:

<?php
class bp_model extends CI_Model {

    function dotpoints($badge_id) {
        $query = $this->db->query("SELECT * FROM course_topic_dotpoints WHERE badge_id = ".$badge_id);

        if ($query->num_rows() > 0) {
            return $query->result();
        }
    }
}
?>

Upvotes: 1

Views: 1621

Answers (2)

stormdrain
stormdrain

Reputation: 7895

Class names must begin with an uppercase letter.

class Badge_progress extends...

class Bp_model extends...

http://codeigniter.com/user_guide/general/controllers.html

http://codeigniter.com/user_guide/general/models.html

update:

You shouldn't have the logic you need as a function in your constructor. Create a separate function to process the dotpoints stuff.

<?php
// Badge Progress Module

class Badge_progress extends CI_Controller 
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('bp_model');

    }

    function dotpoints()
    {
        $data['dotpoints'] = $this->bp_model->dotpoints('1');
        $this->load->view('bp_view', $data);
    }
}

Also, you are missing the constructor in your model. Check out those links I posted earlier...

Upvotes: 0

Sneaksta
Sneaksta

Reputation: 1061

Ah fixed it! Didn't realise that the main controllers (controllers outside of the module directory) also needed to be extending "MX_Controller" instead of "CI_Controller".

Upvotes: 2

Related Questions