Welcome Guest, Not a member yet? Register   Sign In
Struckle with my model and the builder - "Call to a member function get() on null"
#2

Your redefining the database db and builder in your models constructor, the model already has the builder.
just use this->builder where needed. These are already set in the model.

You do not have to tell the builder the model name its in your variables.


PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
EpocheModel extends Model {

    protected $table         'epoche'// your table is auto set here and sent to the model
    protected $primaryKey    'id';
    protected $returnType    'object';
    protected $allowedFields = ['id''name''description''time_begin''time_end''source'];

    public function __construct()
    {
    
parent::__construct();
    }

    public function add($data)
    {
        $query = [
            'parent_id'     => 0,
            'name'          => $data->getVar('label'),
            'description'   => $data->getVar('description'),
            'time_begin'    => $data->getVar('begin'),
            'time_end'      => $data->getVar('end'),
            'source'        => $data->getVar('source')
        ];

        return $this->insert($query);

    }

    public function getAll()
    {
        return $this->builder->get();

    }


What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: Struckle with my model and the builder - "Call to a member function get() on null" - by InsiteFX - 05-15-2021, 05:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB