Why isn't this model returning any values?

By : dmanexe
Source: Stackoverflow.com

I'm trying to build VERY basic model->controller->view structure with CodeIgniter. I'd rather use models (and model functions, more importantly) and controllers than executing queries within each view.

First off, here's the model:

class Leads extends Model {

    function Leads()

    function fetch_leads()
        $query = $this->db->get('leads', 10);
        return $query->result();


Here's the controller, only relevant function being the one in question:

function view()

    $this->load->model('Leads', '', TRUE);

    $data['query'] = $this->Leads->fetch_leads();

$this->load->view('leads/view', $data);

I think the problem is in this line, I may not be passing the data to the view correctly:

$data['query'] = $this->Leads->fetch_leads();

Now, the view:

print_r $data;

Did I mention basic? I'm just trying to get it to pull every field and print it from the database. Yes, the database is configured correctly, and yes, there is data in the database.

EDIT: The model wasn't auto-connecting to the database, so I added that parameter. The model still isn't returning values.

By : dmanexe


You must pass an associative array to the $this-

By : Gabriel

It may be a problem with how you are passing the data to the view. Try to put the $leads in an array.

Ex. $data['leads'] = $this-

it's not gonna work the way you do it.

return $query-

By : Michal M

This video can help you solving your question :)
By: admin