Welcome Guest, Not a member yet? Register   Sign In
Model not using DBGroup
#6

(This post was last modified: 07-31-2021, 09:26 AM by nfaiz. Edit Reason: Add and edit example )

Do you have any other folder in app/Models?

how do you call the model in controller?

PHP Code:
$model = new App\Models\FiscalYears(); 

or

PHP Code:
$model model(FiscalYears::class); 

I don't know is it a bug or not, but we can't use a sub-directory/namespace using model() factories with a same class name.

---- Edit (Add example)---

E.g User Model
PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
User extends Model
{
  protected $DBGroup 'default';
  protected $table 'user';
  protected $primaryKey 'id';


Another User Model
PHP Code:
<?php

namespace App\Models\Admin;

use 
CodeIgniter\Model;

class 
User extends Model
{
  protected $DBGroup 'project';
  protected $table 'user';
  protected $primaryKey 'id';


User Controller
PHP Code:
<?php

namespace App\Controllers;

use 
App\Controllers\BaseController;

class 
User extends BaseController
{
  public function index()
  {
    // No issue
    $user model('User')->findAll();

    // No issue
    $user model('App\Models\User')->findAll();

    // No issue
    $user model(App\Models\User::class)->findAll();

    // This will use app/Models/User.php and DBGroup default is used instead of project.
    $user model('App\Models\Admin\User')->findAll();

    // This will use app/Models/User.php and DBGroup default is used instead of project.
    $user model(App\Models\Admin\User::class)->findAll();
  }

Reply


Messages In This Thread
Model not using DBGroup - by smcintyr - 07-27-2021, 09:02 AM
RE: Model not using DBGroup - by ikesela - 07-27-2021, 12:24 PM
RE: Model not using DBGroup - by smcintyr - 07-27-2021, 01:04 PM
RE: Model not using DBGroup - by InsiteFX - 07-28-2021, 02:58 AM
RE: Model not using DBGroup - by smcintyr - 07-30-2021, 01:02 PM
RE: Model not using DBGroup - by nfaiz - 07-30-2021, 07:46 PM
RE: Model not using DBGroup - by paulbalandan - 07-30-2021, 08:25 PM
RE: Model not using DBGroup - by InsiteFX - 08-01-2021, 01:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB