Welcome Guest, Not a member yet? Register   Sign In
Undefined property after loading a model
#1

[eluser]BrainCatcher[/eluser]
Hi everybody! I'm new here and determent to learn alot!! I'm not new to PHP , but using Codeigniter for the first time, and the MVC end OO structure.

Just made a login system, and the tuts are great!! Even thinking about an plus account.

I run into a problem that is driving me nuts....

Message: Undefined property: Login::$authenticate_model

controller login.php
Code:
<?php

class Login extends Controller{
    
    function index(){
        $this->load->view('includes/header');
        $this->load->view('login_form');        
        $this->load->view('includes/footer');
        
    }
    
    function inloggen()
    {
        $this->load->model('authenticate_model','authenticate_model');
        $query = $this->authenticate_model->user_validate();
        
        if ($query){
            $data = array(
                    'username' => $this->input->post('username'),
                    'is_logged_in' => true
                
                );
                
                $this->session->set_userdata('$data');
                redirect('site');
        }
        
            else{
                
                $this->index();
            }
    }
    
}

?>

Model file authenticate_model.php
Code:
<?php

class Authenticate_model extends Model {
    

    
    function user_validate()
    {
        $this->db->where('fld_username', $this->input->post('username'));
        $this->db->where('fld_password', $this->input->post('password'));
        $query = $this->get('tbl_werknemers');
        
        if ($query->num_rows() == 1){
            
            return true;
        }    
    
    }
}

?>

config.php
Code:
$config['base_url']    = "http://localhost/ci172/";

autoload.php
Code:
$autoload['libraries'] = array('database', 'session');
$autoload['helper'] = array('url','form');

Any help is appreciated. The above code is developed with version CI 1.7.2.

Thanks in advance

Grtz BrainCatcher
#2

[eluser]jedd[/eluser]
Hi BrainCatcher and welcome to the CI forums.

The manual for CI Models suggests that you should use upper case. Also you only need the second parameter if you're renaming your model on the fly.

So instead of this:
Quote:
Code:
$this->load->model('authenticate_model','authenticate_model');

.. just try this:
Code:
$this->load->model ('Authenticate_model');
$query = $this->Authenticate_model->user_validate();

Btw, have you shown the full source? If so, you are missing constructor methods, which will bite you soon.
#3

[eluser]BrainCatcher[/eluser]
@jedd Thanks for the provided help

Indeed I posted the complete code (except the viewer offcourse), it is (as you can see) generated from the tutorial made by Jeffrey, CI day 6.

I tried your solution, and it didn't solve the problem. I'm stuck on it for a few hours and tried several alternatives which also didn't work. Searched on this forum and couldn't find a related topic with the exact same issue. The ones i did find where al about bugs and related to earlier versions of CI

So what kind of constructor is missing?

Thnx again...
#4

[eluser]jedd[/eluser]
Controller
Code:
<?php

class Login extends Controller{
    function  __construct ()  {
        parent::Controller();
    }
...


Model

Code:
<?php

class Authenticate_model extends Model {
    function  __construct ()  {
        parent::Model();
    }
...

Oh, this assumes PHP5. (If you're using PHP4 the constructor function name is the same as the class name. But no one uses PHP4 anymore Wink

What error(s) are you getting now?
#5

[eluser]BrainCatcher[/eluser]
Hi Jedd,

The error message is unchanged dispite your effort. I added the constructor codes, the error keeps comming up..

Is the tut of Jeffrey Way PHP4 oriƫnted?

error message:

A PHP Error was encountered
Severity: Notice

Message: Undefined property: Login::$Authenticate_model

Filename: controllers/login.php

Line Number: 19

We're definitely overlooking something i guess..I can't figure it out, what's missing? :grrr:
#6

[eluser]pistolPete[/eluser]
You should enable logging and post the log here:
Code:
$config['log_threshold'] = 3;
#7

[eluser]BrainCatcher[/eluser]
@pistolPete:

If i switch the parameter to any other value than 0, the page blanks...
#8

[eluser]pistolPete[/eluser]
Make sure the log folder is writeable.
You should also enable error_reporting in index.php:
Code:
error_reporting(E_ALL);
#9

[eluser]BrainCatcher[/eluser]
@pistolPete:

You had a point.The "Error Logging Directory Path" wasn't writeable (IIS) and maybe the route to the path wasn't correct. Sow anyway my page got displayed again with the logtreshold value "3". And that naughty error message presented itself on my screen again...Nothing found in the logs folder though.

Thnx for your fast replies pistolPete!! Are we gonna solve it? hope so... :down:

grtz BrainCatcher
#10

[eluser]jedd[/eluser]
Please post your controller and model again, in full.

Be sure to identify line 19 in your controller for us (inline // comment at the end will suffice).




Theme © iAndrew 2016 - Forum software by © MyBB