I'm going to make login page, but it keep telling me Undefined property '$M_Auth'
when I'm trying to define my model, it's work well in my last project, but now when I open the last project this message is also occurred.
This is my Auth Controller
<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use App\Models\M_Auth;
class Auth extends BaseController
{
public function __construct()
{
$this->M_Auth = new M_Auth();
}
public function index(){
echo form_open();
return view('Auth/login');
}
public function cek_login(){
if($this->validate([
'username' => [
'label' => 'Nama Pengguna',
'rules' => 'required',
'errors' =>[
'required' => '{field} tidak boleh kosong!'
]
],
'password' => [
'label' => 'Kata Sandi',
'rules' => 'required',
'errors' =>[
'required' => '{field} tidak boleh kosong!'
]
]
])){
//jika valid
$username = $this->request->getPost('username');
$password = $this->request->getPost('password');
$cek = $this->M_Auth->login($username, $password);
}else{
}
}
}
This is M_Auth model
<?php
namespace App\Models;
use CodeIgniter\Model;
class M_Auth extends Model
{
protected $DBGroup = 'default';
protected $table = 'pengguna';
protected $primaryKey = 'id_pengguna';
protected $useAutoIncrement = true;
protected $allowedFields = ['level_id', 'username', 'password'];
public function login($username, $password){
return $this->db->table('pengguna')->where([
'username' => $username,
'password' => $password
])->get()->getRowArray();
}
}
Idk what's wrong, tried to fix it by watch tutorial on ytb but it doesn't have any different than my code and already search here too but i don't really understand the problem
...
class Auth extends BaseController
{
private M_Auth $M_Auth;
^^^^^^^^^^^^^^^^^^^^^^
public function __construct()
{
$this->M_Auth = new M_Auth();
}
public function index(){
echo form_open();
return view('Auth/login');
}
...