lithium\data\Model::finder PHP Method

finder() public static method

In this example we define and use 'published' finder to quickly retrieve all published posts. Posts::finder('published', array( 'conditions' => array('is_published' => true) )); Posts::find('published'); Here we define the same finder using an anonymous function which gives us more control over query modification. Posts::finder('published', function($params, $next) { $params['options']['conditions']['is_published'] = true; Perform modifications before executing the query... $result = $next($params); ... or after it has executed. return $result; }); When using finder array definitions the option array is _recursivly_ merged (using Set::merge()) with additional options specified on the Model::find() call. Options specificed on the find will overwrite options specified in the finder. Array finder definitions are normalized here, so that it can be relied upon that defined finders are always anonymous functions.
See also: lithium\util\Set::merge()
public static finder ( string $name, string | callable | null $finder = null ) : callable | void
$name string The finder name, e.g. `'first'`.
$finder string | callable | null The finder definition.
return callable | void Returns finder definition if querying, or void if setting.
    public static function finder($name, $finder = null)
    {
        $self = static::_object();
        if ($finder === null) {
            return isset($self->_finders[$name]) ? $self->_finders[$name] : null;
        }
        if (is_array($finder)) {
            $finder = function ($self, $params, $chain) use($finder) {
                $params['options'] = Set::merge($params['options'], $finder);
                return $chain->next($self, $params, $chain);
            };
        }
        $self->_finders[$name] = $finder;
    }