Hacker News new | past | comments | ask | show | jobs | submit login

A couple ways to do that date thing in CakePHP (ymmv and of course you may not like the options):

  - Use the db schema to enforce a value: "ON INSERT/UPDATE CURRENT_TIMESTAMP". Note that doing so will not allow you to simply set an arbitrary column to the current timestamp

  - Use the php `date()` function. Your server time should be UTC, your app time should be UTC, your datastore time should be UTC. Doing anything else is poor practice. And if you can't do this because your Sysadmin is stupid, fire him and get a new one. This is how the created/modified fields work.

  - Use created/modified fields. These obviously won't work if you want some random field to be the current time that isn't actually the created/modified field, but I cannot for the life of me think of such a use-case.

  - Use "DboSource::expression('NOW()');" as the value of the column. A little more verbose than just doing "NOW()", but at least it won't be interpreted as a string when saved by the "ORM".
I think the biggest problem with PHP is developers not truly understanding the API they are using, and then writing spaghetti code that happens to work. Ease-of-use backfires, since your code actually works and you have no intention of learning to improve it.

Also, I recommend doing "md5($salt) . $password" to hash passwords. Set $salt to 4, I guarantee that is a random number. ;)




Use the php `date()` function. Your server time should be UTC, your app time should be UTC

I think that this is advice that should never be given; it's too easy for someone else to change the timezone PHP uses somewhere else in the code. I agree that the servers should all be on UTC - and sync'd at that! - but it's unrealistic to hope that this will be the case in all instances; I've seen all kinds of weirdness from clients' codebases after taking their first steps off shared hosting / "my first VPS."

Use "DboSource::expression('NOW()');"

Basically, the only realistic option - and last time I searched (I admit, a while ago) really buried away ;)

I think the biggest problem with PHP is developers not truly understanding the API they are using, and then writing spaghetti code that happens to work.

Agree 100% with you. From some of the client code I've repaired, I've also stumbled over PHP developers apparently not understanding the very basics of programming, and crossing their fingers when it comes to running it ;)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: