Welcome Guest, Not a member yet? Register   Sign In
Shield with Oracle - get date format error
#4

(This post was last modified: 11-15-2023, 03:27 PM by [email protected].)

Just to help out anyone who might be having trouble with their date formats: Once I got past my confusion, as mentioned above, it turned out that I did still have a date format issue. What it comes down to is that if your database is configured in such a way that it won't accept a datetime in the format Y-m-d H:iConfused then you will get an error with Shield simply because Shield extends CI4 BaseModel for inserting and updating data, and the CI4 BaseModel methods 'timeToDate' and 'intToDate' assert the datetime format as Y-m-d H:iConfused'

In order to override these methods, you can create a UserModel in your app directory that extends Shield's UserModel (class UserModel extends \CodeIgniter\Shield\Models\UserModel) containing only the 'timeToDate' and 'intToDate' methods, using whatever date formats you need. You'll also want to include Shield's 'updateActiveDate' method to use the same custom date format. Since this model will only contain these 3 methods, it's no big deal to set your custom date format into each one, but for a more elegant solution you can set your date format into a config file and have your 3 methods reference that, so you'd only have to specify it once.

Then go to App/Controllers/AuthController.php and replace 'use CodeIgniter\Shield\Models\UserModel;' with 'use App\Models\UserModel;' This will override the three methods mentioned above, preserving everything else as is. This approach saves you from having to change any files in your vendor folder, which you want to avoid because such changes would be lost when you do a Composer update.

This has enabled me to register new users without hitting the date format error. I don't know if there are other instances in Shield that will run into this date format problem, but I assume they could be fixed by continuing along the lines of the above approach.
Reply


Messages In This Thread
RE: Shield with Oracle - get date format error - by [email protected] - 11-15-2023, 03:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB