Model not using DBGroup |
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
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.
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() {
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?
07-30-2021, 07:46 PM
(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 Another User Model PHP Code: <?php User Controller PHP Code: <?php
Try renaming your .env file to env and see if it will pull thedatabase config settings.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |