github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

mcurry / find

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 10
    • 2
  • Source
  • Commits
  • Network (2)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

CakePHP Plugin - Create custom find types by just defining functions — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

fixed up readme 
mcurry (author)
Fri Jun 05 19:45:44 -0700 2009
commit  aecd4f6e311ce260a3fbf5f31ac45cdd69092a97
tree    1b35fc2de0a8ba0c666393886494fabc05c70d61
parent  4dfd2ad3e0165ec45663d93aa5e1f79d6dd2f475
find /
name age
history
message
file README Fri Jun 05 19:45:44 -0700 2009 fixed up readme [mcurry]
directory tests/ Wed Apr 29 21:52:50 -0700 2009 made into plugin [unknown]
directory vendors/ Fri Jun 05 19:42:28 -0700 2009 added pagination support [mcurry]
README
/*
 * 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 <matt@pseudocoder.com>
 * @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.
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server