-
Hi. I am having trouble with creating user model instance. I use Myth\Auth UserModel to auth processes and I use my own UserModel to do other stuff in my ci4 project. I have php code as following: <?php namespace App\Controllers;
use CodeIgniter\Config\Factories;
use \Myth\Auth\Models\UserModel as MythUserModel;
use App\Models\UserModel as AppUserModel;
class Home extends BaseController
{
public function index()
{
echo("Class Names");
d(MythUserModel::class); // I expect myth user model
d(AppUserModel::class);
echo("Models with helper");
d(model(MythUserModel::class)); // I expect myth user model
d(model(AppUserModel::class));
echo("Models with factories");
d(Factories::models(MythUserModel::class)); // I expect myth user model
d(Factories::models(AppUserModel::class));
echo("Models with factories (str)");
d(Factories::models('\Myth\Auth\Models\UserModel')); // I expect myth user model
d(Factories::models('\App\Models\UserModel'));
// all outputs are 'App\Models\UserModel'
}
} output is here: When I explicitly specify I also read ci4 docs (user guide) but did not help. Note: my english is not very good. Let me know if I made a mistake. EDIT1: I created simple project if you would like to look at https://github.com/hatsat32/ci4-demo-app/blob/master/app/Controllers/Home.php |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I think you are misunderstanding When this is set (which is default), I you already know the model you want it's never wrong to ask for it directly: $model = new \Myth\Auth\Models\UserModel() If you would still like to take advantage of the shared instances you can turn off the $model = Factories::models('Myth\Auth\Models\UserModel', ['preferApp' => false]); Note: the helper function |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
App
. You could give your version a different name, or put it in a different folder (like app/Auth/UserModel.php). One solution (which might be a good idea) would be to have Myth:Auth use theinstanceOf
flag to make sure it is using a version of its own model - this would ignore your model (assuming it does not extend Myth's).