![]() |
Where to put a function to calculate age...? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Where to put a function to calculate age...? (/showthread.php?tid=24860) |
Where to put a function to calculate age...? - El Forum - 11-22-2009 [eluser]Sinclair[/eluser] Hi, My question is about design in CI. I have my Model with functions that do SELECTS to the database, but I need also to use functions like this: Code: # Where can I put functions like this in CI? Best Regards, Where to put a function to calculate age...? - El Forum - 11-22-2009 [eluser]jedd[/eluser] This is crying out to take up residence in a [url="/user_guide/general/helpers.html"]helper[/url]. Where to put a function to calculate age...? - El Forum - 11-22-2009 [eluser]Sinclair[/eluser] Thanks. I'am writting a helper but I have some strange errors: The function is this one here: Code: <?PHP I have several errors like this: Quote:A PHP Error was encountered Quote:A PHP Error was encountered The HELPER is working but display these errors... what can I do to solve this? Best Regards, Where to put a function to calculate age...? - El Forum - 11-22-2009 [eluser]CI Coder[/eluser] Well, it depends when you need it and how broad a scope you want. If you need it in all controllers and models, etc., put it in a helper file; if you only need it in that model leave it only there. The latter option makes portability a bit easier in the sense that you don't have to remember to move the helper file with the model all the time, but that's minor. Where to put a function to calculate age...? - El Forum - 11-22-2009 [eluser]Sinclair[/eluser] I think the best solution is to use a HELPER. But how to fix the errors? Best Regards. Where to put a function to calculate age...? - El Forum - 11-22-2009 [eluser]CI Coder[/eluser] [quote author="Sinclair" date="1258947899"]Thanks. I'am writting a helper but I have some strange errors: The function is this one here: Code: <?PHP I have several errors like this: Quote:A PHP Error was encountered Quote:A PHP Error was encountered The HELPER is working but display these errors... what can I do to solve this? Best Regards,[/quote] Go into your php.ini and set the default time zone for your PHP installation. Add a line like "date.timezone = GMT". Where to put a function to calculate age...? - El Forum - 11-22-2009 [eluser]jedd[/eluser] The date change happened in 5.3.x from memory - confused a few people. Previously PHP had made a few assumptions on our behalf, but now they're not being so assumptive ... pluses and minuses. The other error you're seeing - did you check your incoming date has two /'s in it? I'd be putting an echo in there just to check what you've got coming in. Alternatively dump it into a straight array (not using list()) and then access the fields directly. Where to put a function to calculate age...? - El Forum - 11-22-2009 [eluser]Sinclair[/eluser] The first error was solved in the php.ini. The second error was solved changing this line from: This Code: list($Year, $Month, $Day) = explode("/", $BirthDate); To This Code: list($Year, $Month, $Day) = explode("-", $BirthDate); Thanks a lot for your help. Best Regards. Where to put a function to calculate age...? - El Forum - 11-22-2009 [eluser]CI Coder[/eluser] Yes, MySQL date is always stored as YYYY-MM-DD. Glad it worked out for you. |