Welcome Guest, Not a member yet? Register   Sign In
Undefined Property on Model call
#1

[eluser]anndr0id[/eluser]
I searched the forums and couldn't find any solution to this issue.

The error I'm receiving is thus:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: User_model::$get_countries
Filename: users/register.php
Line Number: 13

LAMP environment, PHP5, Most recent version of CodeIgniter

I've tried calling the model from both the construct and the function, and get the same error, always at line 13 which is:

Code:
$countries = $this->userdb->get_countries;

I've tried calling the database in different ways, not renaming the model, etc. with no success.

Code is as follows for register.php controller:
Code:
class Register extends Controller {
    
    function __construct() {
            parent::Controller();
            $this->load->model('User_model', 'userdb', TRUE);
       }
    
    function index() {
        //create the country dropdown
        $countries = $this->userdb->get_countries;    // THIS IS LINE 13    
        foreach ($countries as $row) {
                $data['countrySelect'] .= '<option value="'.$row->ID.'" '. set_select('country', $row->ID). '>'.$row->name.'</option>';
        }
        
        //load view
        $this->load->view('users/register_view', $data);
    }
}

and this is the model with offending function:

Code:
class User_model extends Model {
    
    function User_model() {
        parent::Model();
    }
    
    //get country menu
    function get_countries() {
        $query = $this->db->get('country');    
        return $query->result();
    }
}

I'm stumped. Any clues? Thanks in advance for your insight Smile
#2

[eluser]Craig A Rodway[/eluser]
The clue is in the error Wink

Quote:Message: Undefined property: User_model::$get_countries

You are trying to access/set a property (variable) of the model; not calling a function. To call a function you need to include the brackets, thus:

Code:
$countries = $this->userdb->get_countries();
#3

[eluser]anndr0id[/eluser]
Duh! Haha - of course, I've obviously been coding for too long today.. its always the little things when you're tired.

Thank you very much Wink
#4

[eluser]Craig A Rodway[/eluser]
No problem, I think we've all been there Smile Get some coffee, have a break, maybe even some fresh air Tongue




Theme © iAndrew 2016 - Forum software by © MyBB