Fetching a random database entry with cakePHP
Date: Wed, Feb 18th 2009, 17:07 Author: nick Views: 2918 Comments: 1 share
Using AppModel to write our wrapper findRandom function allows us to retrieve a random record from any model we choose.
Since we're using AppModel which all models extend from, we can use findRandom in any cake model.
Example:
- class AppModel extends Model {
- function findRandom(){
- $this->id = null;
- }
- }
Since we're using AppModel which all models extend from, we can use findRandom in any cake model.
Example:
- $random_post = $this->Post->findRandom();
