![]() |
Modifying data from database before building the result array - 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: Modifying data from database before building the result array (/showthread.php?tid=80178) |
Modifying data from database before building the result array - Sinclaire - 09-23-2021 I'm planning to create an API for CRUD operations. Retrieving data from the database works flawlessly as usual and also returning is no issue. But when it comes to dates, I'm facing issues with the format. The dates are stored as DATETIME in the database and are automatically created at insert, but I want to deliver an unix timestamp when accessing via API. I've stripped down my code to the crucial parts: PHP Code: <?php Code: // Result I know that I could simply select each field in separate and enclose UNIX_TIMESTAMP(create_timestamp) but I'm planning to operate on tables with much more columns in the future as well. Also I may use the query builder instead of custom SQL for more basic selects. I've red about the getCustomResultObject(), but I can't figure out how to use it. RE: Modifying data from database before building the result array - Sinclaire - 09-24-2021 Okay nevermind, I managed to solve it by myself: I figured out I was on the right path. The key to this issue are those entity classes. I added following entity class: PHP Code: // Entities/Config.php PHP Code: // Models/ConfigModel.php Code: // Result RE: Modifying data from database before building the result array - InsiteFX - 09-24-2021 Here are a couple of methods that should do what you want, NOT TESTED. PHP Code: /** Let me know if they work for you. RE: Modifying data from database before building the result array - Sinclaire - 09-24-2021 (09-24-2021, 01:42 AM)InsiteFX Wrote: Here are a couple of methods that should do what you want, NOT TESTED. Thank you for your fast answer! I'm not sure where to put those functions (do they belong in the entity?), but I managed to solve the issue by myself. The Post #2 just needs to be approved. |