Giter Site home page Giter Site logo

find's Introduction

/*
 * CakePHP plugin for create custom find types
 * Copyright (c) 2009 Matt Curry
 * www.PseudoCoder.com
 * http://github.com/mcurry/find
 * http://www.pseudocoder.com/archives/2008/10/24/cakephp-custom-find-queriescakephp-custom-find-types/
 *
 * Thanks to Daniel Salazar for the inspiration on pagination support
 * http://code621.com/content/10/easy-pagination-using-matt-curry-s-custom-find-types
 *
 * @author      Matt Curry <[email protected]>
 * @license     MIT
 *
 */

/* Description */
A CakePHP plugin that allows for creating custom find types by simply adding a new method to the model.

/* Install */
1) Download the plugin to /app/plugin/find

2) Include the FindAppModel in your app_model.php
App::import('Vendor', 'Find.find_app_model');

3) Have your AppModel extend FindAppModel instead of Model
class AppModel extends FindAppModel {

}

/* Usage */
1) Call custom find types with the pattern:
$this->Model->find('custom_find_type');

2) In your model create functions that match the find type with "__find" prefixed and the find type CamelCased:
function __findCustomFindType($options) {
  //do find here
}

/* How To Paginate */
This is pretty simple thanks Daniel Salazar (http://code621.com/content/10/easy-pagination-using-matt-curry-s-custom-find-types)
1) Add "paginate" => true to the $options array will return the $query array, which is suitable for using as your controllers $paginate parameter.  
   You probably want to merge that with the default controller pagination settings.
   $this->paginate = am($this->paginate, $this->Post->find('published', array('paginate' => true)));
   $this->set('posts', $this->paginate());

/* Why This Is A Vendor, Not A Model */
When doing App::import on a model Cake checks that the AppModel class already exists, otherwise it tries to import.  Since the AppModel is depended on the FindAppModel, it won't exist and will try to be included, leading to a infinite loop.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.