Undefined Property Database Error When I've Defined the Property

#1
[eluser]kirkaracha[/eluser]
This works when I define the table name in the constructor:
Code:
class Congress_model extends Model{

    function Congress_model() {
        parent::Model();
        $this->table = 'congress';
    }

    function get_congress_info($url_name = NULL,$id = NULL) {
        $this->db->select('
            id,
            congress_name,
            congress_url_name,
            congress_start_date,
            congress_end_date
        ');
        if(!is_null($url_name)){
            $this->db->where('congress_url_name',$url_name);
        }
        if(!is_null($id)){
            $this->db->where('id',$id);
        }
        $this->db->from($this->table);
        $this->db->orderby('congress_start_date','ASC');
        return $this->db->get();
    } // get_congress_info

This doesn't work:
Code:
class Census_model extends Model{

    function Census() {
        parent::Model();
        $this->table = 'census';
    }

    function get_census_info($state_id = NULL,$census_year = NULL) {
        $this->db->select('
            id,
            state_id,
            census_year,
            census_total_population
        ');
        if(!is_null($census_year)){
            $this->db->where('census_year',$census_year);
        }
        if(!is_null($state_id)){
            $this->db->where('state_id',$state_id);
            $this->db->limit(1);
        }
        $this->db->from($this->table);
        $this->db->orderby('census_year','ASC');
        return $this->db->get();
    } // get_census_info

I get an "Undefined property: Census_model::$table" error message on the line $this->db->from($this->table); How can it work in one and not in the other? I duplicated the working Congress_model and changed the table and field names. I've double-checked them and they're all correct.

#2
[eluser]danmontgomery[/eluser]
Code:
class Census_model extends Model{

    function Census() {

the member function Census() doesn't automatically get run in the class Census_model.

#3
[eluser]kirkaracha[/eluser]
Thank you! I've been staring at it so long I couldn't see it.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.