I have a model 'listing' with a field 'created' which is in a datetime format. I need to list in a view all listings that were created over 2 weeks ago. An extra thing if possible is to somehow mark them as expired.
This is in cakePhp 1.27
I have a model 'listing' with a field 'created' which is in a datetime format. I need to list in a view all listings that were created over 2 weeks ago. An extra thing if possible is to somehow mark them as expired.
This is in cakePhp 1.27
Hi I think you can use a simple script to do that in cake.
function meScript(){
// first load your model if necessary
$listingModel = ClassRegistry::init('Listing');
// Then set your date margin to , two weeks back
$date_margin = date("Y-m-d H:i:s", strtotime('-2 week')) ;
// now retrieve all records that were created over 2 weeks ago
$listings = $listingModel ->find('all', array(
'conditions' => array('created <' => $date_margin),
)
);
}
That's pretty much it. Since the margin date is in "Y-m-d H:i:s" format, the " 'created <' => $date_margin" condition will retrieve all records that were created before that date.
As for the next step of marking them as expired: Simply loop through the results and use their ids to set your 'expired' field (or whatever it is called in your database table) to 'true'.