Welcome Guest, Not a member yet? Register   Sign In
Call to a member function getDefaultValues() on null error
#1
Photo 

My login controller has an error, I don't know why but the Windows system runs fine as if Linux has an error

Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: Login::$login
Filename: controllers/Login.php
Line Number: 11


Quote:An uncaught Exception was encountered
Type: Error
Message: Call to a member function getDefaultValues() on null
Filename: /var/www/html/sms/application/controllers/Login.php
Line Number: 11

Controller:
PHP Code:
<?php
class Login extends MY_Controller
{
    public function 
index ()
    
 
   {
 
       $input = (object) $this->input->post(nulltrue);
 
       if (! $_POST
 
       
        
{
 
           $input = (object) $this->login->getDefaultValues();
 
       }
 
                
        if 
(! $this->login->validate()) {
 
           $this->load->view('login/form'compact('input'));
 
           return;
 
       }

 
       if ($this->login->login($input)) {
 
           redirect(base_url(), 'refresh');
 
       }

 
       flashMessage(
 
           'error',
 
           'Username atau password salah.
             Atau akun anda sedang diblokir.'
 
       );
 
       redirect('login''refresh');
    }

    public function 
logout()
    {
 
       $this->login->logout();
 
       redirect(base_url(), 'refresh');
    }


LogiModel:

PHP Code:
<?php
class LoginModel extends MY_Model
{
 
   public $table 'user';

 
   public function getValidationRules()
 
   {
 
       $validationRules = [
 
           [
 
               'field' => 'username',
 
               'label' => 'Username',
 
               'rules' => 'trim|required'
 
           ],
 
           [
 
               'field' => 'password',
 
               'label' => 'Password',
 
               'rules' => 'trim|required'
 
           ],
 
       ];

 
       return $validationRules;
 
   }

 
   public function getDefaultValues()
 
   {
 
       return [
 
           'username' => '',
 
           'password' => ''
 
       ];
 
   }

 
   public function login($input)
 
   {
 
       $input->password md5($input->password);

 
       $user $this->db->where('username'$input->username)
 
                        ->where('password'$input->password)
 
                        ->where('isBlokir''n')
 
                        ->limit(1)
 
                        ->get($this->table)
 
                        ->row();

 
       if (count($user)) {
 
           $data = [
 
               'username' => $user->username,
 
               'level'    => $user->level,
 
               'isLogin'  => true,
 
               'userID'   => $user->ID
            
];
 
           $this->session->set_userdata($data);
 
           return true;
 
       }

 
       return false;
 
   }

 
   public function logout()
 
   {
 
       $data = ['username''level''isLogin''userID'];
 
       $this->session->unset_userdata($data);
 
       $this->session->sess_destroy();
 
   }


I beg you please answer why is my login error?
Reply
#2

Your model filename needs to be UCfirst, i.e. Loginmodel, not LoginModel.
Linux is case-sensitive, whereas Windows lets you get away with not following the expected naming.
This is a Windows problem, not a Linux error Undecided
Reply
#3

I changed the name of the file but it doesn't work too?
Reply
#4

You refer to a variable $login, which does not appear to be initialized.
It appears that you expect it to refer to your Loginmodel, which would happen if your controller had
Code:
$this->load->('loginmodel','login');

See https://www.codeigniter.com/user_guide/l...der::model
Reply
#5

the code works with thanks Smile
Reply
#6

if this code is how naming is in linux because 404 Page Not Found, the model name is SmsBroadcastmodel.php

I beg you please answer

Code:
$this->load->model('SmsBroadcastmodel','smsbroadcast');
Reply




Theme © iAndrew 2016 - Forum software by © MyBB