Fetching a random database entry with cakePHP
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();