Skip to content

mobvox/CustomFinds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

Custom Finds Behavior

A CakePHP behavior that enables you to configure custom finds in your Model classes in order to use with Model::find()

Installation

Git clone or copy the plugin into app/plugins/custom_finds

To enable this behavior for all your models, add it to your AppModel.

<?php
class AppModel extends Model {
    var $actsAs = array('CustomFinds.CustomFinds');
}
?>

Usage

Model:

<?php
class Product extends AppModel {

    // Only necessary if you haven't initialized the behavior in your AppModel
    var $actsAs = array('CustomFinds.CustomFinds');

    var $customFinds = array(
        'topSellers' => array(
            'fields' => array('Product.name','Product.price'),
            'contain' => array('ProductImage.source'),
            'conditions' => array('Product.countSeller >' => 20, 'Product.is_active' => 1),
            'recursive' => 1,
            //All other find options
        )
    );

}
?>

Controller:

<?php
class ProductsController extends AppController {

var $paginate = array( ‘custom’ => ‘topSellers’, //‘conditions’ => array(…), //… ); function index(){ $findAll = $this→Product→find(‘all’, array( ‘custom’ => ‘topSellers’, ‘conditions’ => array(‘Product.category_id’ => 2) )); $findFirst = $this→Product→find(‘first’, array( ‘custom’ => ‘topSellers’ )); $findCount = $this→Product→find(‘count’, array( ‘custom’ => ‘topSellers’ )); }

}
?>

Releases

No releases published

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •  

Languages