Load Dynamic Model |
Hello
I would like use a dynamic model, i want use loop to load multiple model dynamically, in CI3 work fine and in CI4 doesn't work this is an example $array = array("Roles"); foreach ($array as $key => $value) { $UsersModel = new RolesModel(); // this work fine $module = $key.'Model'; $module = new $module(); // this return error : Class 'RolesModel' not found } can you help me !
Add the "use" statement above your class.
I.e. use App\Models\RolesModel; class x extends Controller { }
(02-13-2020, 01:49 PM)falko Wrote: Add the "use" statement above your class. This is top of my Controller : Code: namespace App\Controllers; so when i use this syntax Code: $UsersModel = new RolesModel(); wheen Code: $variable = "NameOfModel"; any idea !!
finally i found a solution for this problem
we have to must declare the full namespace path of a class Code: namespace App\Models for help thx
(02-13-2020, 04:43 PM)lahoussaine Wrote: finally i found a solution for this problem if you are in controller then you need something like this $m="\App\Models".'\\'.$j['model']; $model=new $m(); |
Welcome Guest, Not a member yet? Register Sign In |