CodeIgniter Forums
BUG model common function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: BUG model common function (/showthread.php?tid=76437)



BUG model common function - cukikt0302 - 05-12-2020

PHP Code:
$Gg model$this->modelGG );
$Gi model$this->modelGI );
var_dump(['gg' => $Gg->table'gi' => $Gi->table])
new 
$this->modelGG;# Worked
new $this->modelGI;# Worked 
print the same name of TABLE   Exclamation


RE: BUG model common function - jreklund - 05-12-2020

Hi, what does $this->modelGG and $this->modelGI contain?


RE: BUG model common function - cukikt0302 - 05-12-2020

PHP Code:
Crud.php
<?php namespace BAPI\Models\GI;

class Crud extends \CodeIgniter\Model
{
  protected $table = 'gitem';
  protected $primaryKey = 'id';
  protected $returnType = 'array';
  protected $dateFormat = 'date';

  protected $useSoftDeletes = true;
  protected $useTimestamps = true;

Crud.php
<?php namespace BAPI\Models\GG;

class Crud extends \CodeIgniter\Model
{
  protected $table = 'ggroup';
  protected $primaryKey = 'id';
  protected $returnType = 'array';
  protected $dateFormat = 'date';

  protected $useSoftDeletes = true;
  protected $useTimestamps = true



RE: BUG model common function - cukikt0302 - 05-12-2020

Oops im sr my bad
It worked!
Im forgot set 2nd ARG to false

$Gg = model( $this->modelGG, false );
$Gi = model( $this->modelGI, false );
var_dump(['gg' => $Gg->table, 'gi' => $Gi->table])


RE: BUG model common function - jreklund - 05-12-2020

Okey, what does $this->modelGG contain?

protected = 'BAPI\Models\GG\Crud' or something else?


RE: BUG model common function - cukikt0302 - 05-12-2020

It contain
protected $modelGG = '\BAPI\Models\modelGG\Crud';
protected $modelGI = '\BAPI\Models\modelGI\Crud';


RE: BUG model common function - jreklund - 05-12-2020

That's odd, it should only be shared on model level, so that you only load GG ones. But it looks like it's picking up something else, maybe the Crud name and assign the previous model again.


RE: BUG model common function - cukikt0302 - 05-12-2020

I think so. Seems like forgot to delete the old model or something similar.

PHP Code:
if (($pos strrpos($name'\\')) !== false)
{
    
$class substr($name$pos 1);

I remove all this line it worked Smile


RE: BUG model common function - jreklund - 05-12-2020

Hi could you try the following (revert the changes made to ModelFactory):
PHP Code:
protected $modelGG '\\BAPI\\Models\\modelGG\\Crud';
protected 
$modelGI '\\BAPI\\Models\\modelGI\\Crud'

Do you get the same result?

EDIT: nvm, that should be an escape for \ namespace. Will need to try it out in the weekend.


RE: BUG model common function - cukikt0302 - 05-12-2020

(05-12-2020, 01:10 PM)jreklund Wrote: Hi could you try the following (revert the changes made to ModelFactory):
PHP Code:
protected $modelGG '\\BAPI\\Models\\modelGG\\Crud';
protected 
$modelGI '\\BAPI\\Models\\modelGI\\Crud'

It not working bro