Welcome Guest, Not a member yet? Register   Sign In
Missing Model
#1

(This post was last modified: 10-10-2024, 01:30 AM by evo_king99.)

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();
    }
}
Reply
#2

Rewrite namespace to App\*
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

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

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 ?
CMS CI4 A CMS system, runs out of the box written on top of CI4
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Reply
#5

(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
Reply
#6

ok as long as its working
CMS CI4 A CMS system, runs out of the box written on top of CI4
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Reply
#7

Your model class name first character should be in upper case Absen
and saved with first letter upper case.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB