zen of coding

Remember $this!

Do you need to get some information about your current state of the cake app?… Maybe find out the name of the current layout? Or see what helpers are currently loaded? Need session time?… etc., etc. $this contains a lot of usefull information. Just try it in your beforeRender() in[…]

Read More »

Build a string from a resultset array

Sometimes it’s very handy to be able to quickly build a string from CakePHP’s resultset array. For example you want to build a string of ID’s to be used with the “IN” condition in your DB (such as Profile.id IN(1,2,3,4)… ). Let’s say we did a find(‘all’… and got an array[…]

Read More »

I need the first record from my table…

Let’s say you need to know when was the very first user record created. Add a method like this to your User model (assuming you have a ‘created’ field): [sourcecode language=’php’] function getFirstDay() { return $this->find(‘first’, array( ‘fields’ => array(‘created’), ‘order’ => ‘User.created ASC’)); } [/cc] Try in the controller:[…]

Read More »

Array from XML in CakePHP

Update (9/9/2008): Since the writing of this post, there is now a nicer way to handle this, which David Persson kindly pointed out: $Xml = new Xml($rawXML); $Xml->toArray(); For historical reference and if you don’t have the latest and greatest CakePHP core, here’s the “old method”… On IRC gwoo posted[…]

Read More »
%d bloggers like this: