I updated from 4.46 to 4.5.1, I've made all the changes to every file in every upgrade from 4.4.6 to 4.5.1 and everything works except this one
The model works for both methods only with the construct
So how should I do to be able to use $this->db->table('mytable') ?
PHP Code:
<?php
namespace App\Models;
use CodeIgniter\Model;
class My_model extends Model
{
protected $table = 'my_table';
protected $primaryKey = 'id';
protected $allowedFields = [
'field_1',
'field_2',
'field_3',
'field_4',
];
public function test_1()
{
$result = $this->select('field_1, field_2')
->where('id', 1)
->get()
->getRow();
}
public function test_2()
{
$user = $this->db->table('user')
->select('name, surname')
->where('id', 1)
->get()
->getRow();
}
}
or
PHP Code:
<?php
namespace App\Models;
use CodeIgniter\Model;
class My_model extends Model
{
public function test_1()
{
$result = $this->db->table('product')
->select('field_1, field_2')
->where('id', 1)
->get()
->getRow();
}
public function test_2()
{
$user = $this->db->table('user')
->select('name, surname')
->where('id', 1)
->get()
->getRow();
}
}
For example, if I have a model like this, how do I make the test_2 method work?
The test_2 method gives me the error: Call to a member function table() on null
if instead I put the construct both works
PHP Code:
public function __construct()
{
parent::__construct();
}