Welcome Guest, Not a member yet? Register   Sign In
Fail when loading a model
#1
Shocked 
(This post was last modified: 03-05-2022, 05:05 AM by yoshi.)

Hi, I'm trying to make a record.
I refer to here on the official page.
create-a-form

Why am I getting this error even though I'm loading the exact same model?

PHP Code:
(SchoolLessonController.php)
class 
SchoolLessonController extends BaseController
{
    /**
    * @return string
    */
    public function index(): string
    
{
        $model model(LessonModel::class);      // <- point A
        $data['lessons'] = $model->findAll();
        
        
// List of grades
        return view("school/lesson/list"$data);
    }
    
    
/** 
    * @param int $groupId
    * @return string
    */
    public function detail(int $groupId): string
    
{
        $data = ["group_id" => $groupId];
    
        
// Details of a class
        return view("school/lesson/detail"$data);
    }
    
    
/**
    * @throws ReflectionException
    */
    public function create(): RedirectResponse|string
    
{
        $model model(LessonModel::class);     // <- point B
        $rules = [
            'title' => 'required|min_length[3]|max_length[255]',
            'body'  => 'required',
        ];
        
        
if ($this->request->getMethod() === 'post' && $this->validate($rules)) {
            $data = [
                'title' => $this->request->getPost('title'),
                'body' => $this->request->getPost('body'),
            ];
            $model->save($data);
        
            
// If you want to create continuously, redirect to create. If not, redirect to list.
            return redirect('school/lesson/create/success'$data);
        } else {
            $data = [
                'title' => null,
                'body' => null,
            ];
        }
    
        
return view('school/lesson/create'$data);
    }

Reply
#2

Update CI version to 4.1.9
Reply
#3

(03-06-2022, 07:37 AM)iRedds Wrote: Update CI version to 4.1.9

thanks, iRedds. Thank you as always.

exact it was fixed. my codeigniter version had 4.1.6
Reply




Theme © iAndrew 2016 - Forum software by © MyBB