Model not using DBGroup - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Model not using DBGroup (/showthread.php?tid=79794) |
Model not using DBGroup - smcintyr - 07-27-2021 I searched the forums but it does not appear anyone else is having this issue. I am using the myth-auth module to provide authentication to my system. To keep things logically separated, I have a separate database for the authentication module and a separate database for my data. I have configure the myth-auth module to use the 'default' database group, and I'm trying to configure CodeIgniter 4 to use another database for the data. Here is what I have. .env Code: database.default.hostname = localhost /app/Config/Database.php PHP Code: public $default = [ /app/Models/FiscalYearModel.php PHP Code: <?php namespace App\Models; mysqli_sql_exception #1146 Table 'users.FiscalYears' doesn't exist RE: Model not using DBGroup - ikesela - 07-27-2021 I did test on my code, it work perfectly with DBGroup, better check your db connection, seem like the connection fallback to default. maybe failed to connect to db publications. RE: Model not using DBGroup - smcintyr - 07-27-2021 As far as I can tell the database connection is working correctly. For instance in my controller I can use the following code and get data returned. PHP Code: public function index() { RE: Model not using DBGroup - InsiteFX - 07-28-2021 make sure the name is spelled correct and that the case is correct. RE: Model not using DBGroup - smcintyr - 07-30-2021 I have triple checked the names, and they are identical. I even went so far as to copy paste database names. I also created a brand new CI project that does not use the myth-auth module just in case this was causing a conflict somehow. But I still encounter the same error. Where does the group name for $DBGroup in the model correspond to? Does it correspond to the App\Config\Database.php or the .env file? RE: Model not using DBGroup - nfaiz - 07-30-2021 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 Another User Model PHP Code: <?php User Controller PHP Code: <?php RE: Model not using DBGroup - paulbalandan - 07-30-2021 Can you share the full stack trace? RE: Model not using DBGroup - InsiteFX - 08-01-2021 Try renaming your .env file to env and see if it will pull thedatabase config settings. |