CodeIgniter Forums
Missing Model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Missing Model (/showthread.php?tid=91785)



Missing Model - evo_king99 - 10-10-2024

hi, i just try to make attandance app for my school library but my app cant find my model when i call it in controler.

here is my controler

Code:
<?php

namespace App\Controllers;

use app\Models\AbsenModel;
use app\Models\SiswaModel;

class absen extends BaseController
{
    protected $absenmodel;
    protected $siswamodel;

    public function __construct()
    {
        $this->absenmodel = new AbsenModel();
        $this->siswamodel = new SiswaModel();
    }

    public function index(): string
    {
        return view('perpus/Dashboard.php');
    }

    public function save()
    {
        $ids = $this->request->getvar('ids');
        $date = now();
        $nama = $this->siswamodel->getnama($ids);
        $kelas = $this->siswamodel->getkelas($ids);
        $this->absenmodel->save([
            'idsiswa' => $ids,
            'nama' => $nama,
            'kelas' => $kelas,
            'date' => $date
        ]);
        return redirect()->to('/Absensi');
    }

    public function absensi()
    {
        $data =
            [
                'absen' => $this->absenmodel->getuser()
            ];
        return view('perpus/viewabsen', $data);
    }
}

and this is my model

Code:
<?php

namespace App\Models;

use CodeIgniter\Model;

class AbsenModel extends Model
{
    protected $table = 'absen';
    protected $useTimestamps = true;
    protected $allowedFields = ['idsiswa', 'nama', 'kelas', 'date'];

    public function getuser($id = false)
    {
        if ($id == false) {
            return $this->findAll();
        }
        return $this->where(['id' => $id])->nama();
    }
}



RE: Missing Model - ozornick - 10-10-2024

Rewrite namespace to App\*


RE: Missing Model - evo_king99 - 10-10-2024

(10-10-2024, 01:40 AM)ozornick Wrote: Rewrite namespace to App\*
doesn't work, it keep sending warning unexpected"\"


RE: Missing Model - captain-sensible - 10-10-2024

if you had in controller :

Code:
use App\Controllers\BaseController;
use CodeIgniter\Controller;
use \App\Models\AbsenModel;
use  \App\Models\SiswaModel;

and in models

Code:
namespace App\Models;

use CodeIgniter\Model;
use CodeIgniter\Database\ConnectionInterface;
class AbsenModel extends Model
{

what would happen ?


RE: Missing Model - evo_king99 - 10-10-2024

(10-10-2024, 03:52 AM)captain-sensible Wrote: if you had in controller :

Code:
use App\Controllers\BaseController;
use CodeIgniter\Controller;
use \App\Models\AbsenModel;
use  \App\Models\SiswaModel;

and in models

Code:
namespace App\Models;

use CodeIgniter\Model;
use CodeIgniter\Database\ConnectionInterface;
class AbsenModel extends Model
{

what would happen ?
thank you so much, i don't know what happen but it just work like magic. i think the basecontroller need to be called but before i post this and try this, it doesn't work


RE: Missing Model - captain-sensible - 10-10-2024

ok as long as its working


RE: Missing Model - InsiteFX - 10-10-2024

Your model class name first character should be in upper case Absen
and saved with first letter upper case.