CakePHP set CreatedAt field on save

So after a quick search I found that CakePHP automatically updates ‘created’ and ‘modified’ for you. Well the database I already had setup uses the fields ‘CreatedAt’ and ‘UpdatedAt’ instead. I didn’t want to go through and modify almost every table in the database just so I don’t have to set the CreatedAt date manually with every new record.

So to make sure I get CreatedAt set on new records I added this to my AppModel.php

public function beforeSave($options = array()) {
        if(!isset($this->data[$this->alias]['id'])) {
                $this->data[$this->alias]['CreatedAt'] = date("Y/m/d H:i:s");

Before the data is actually saved and if there is no id, since new records wouldn’t have one yet, it sets ‘CreatedAt’ to the current time. If there is a way to change ‘created’ to ‘CreatedAt’ I would prefer to do that, but this is working for me at the moment.

Because ‘UpdatedAt’ is set to update to the current timestamp on update through the database, I don’t have to worry about CakePHP doing it for me.

LibreOffice Get URL From Hyperlink

So I like using spreadsheets to mash data with, using the formulas there allow me to generate repetitive tasks easily.  This time I needed to map some Ids together, but they were in the URL of hyperlinks.  So I created the following macro to retrieve the URL from the hyperlink object in libreoffice.

REM s = sheet, c = column, r = row
Function GETURI(s,c,r)
dim doc as object
dim sheet as object
dim mycell as object

doc = ThisComponent
sheet = doc.Sheets(s)
mycell = sheet.getCellByPosition(c,r)

if mycell.Textfields.Count >= 1 then
     GETURI = mycell.getTextfields.getByIndex(0).URL
     GETURI = mycell.Textfields.Count

End Function

Fixed Twitter Feed and Added Listening Links

So since Twitter updated their API, the way that this them pulls feeds wasn’t working anymore, it was really archaic anyway.  Well instead of using one of their embed widget things I created a service on another server of mine that allows for pulling of your last tweets.  You simply give it and it will return XML with your five last tweets, it works from one to twenty.  I currently have the API caching the calls so it doesn’t have completely live data.  I built the service using perl dancer and starman as the server and memcached for caching.  More of an exercise then anything else.

Also added a link category of Listening/Listened to post the current audio books I’m listening to.  I’m a big fan of and the authors that put their stuff up there, so I thought I would share what I’ve listened to.  A good place to start is with authors Nathan Lowell and Scott Sigler.  Their stuff is also available on (Nathan Lowell, Scott Sigler).

Go back to top