src/bundles/Database/Model.php
public static function find( $param = null, $param2 = null ) 
	{
		$settings = static::_model();

		$query = DB::select( $settings['table'] );

		// Do we have a find modifier?
		if ( !is_null( $settings['find_modifier'] ) ) 
		{
			$callbacks = $settings['find_modifier'];

			if ( !\CCArr::is_collection( $callbacks ) )
			{
				$callbacks = array( $callbacks );
			}

			foreach( $callbacks as $call )
			{
				if ( is_callable( $call ) ) 
				{
					call_user_func_array( $call, array( &$query ) );
				}
				else 
				{
					throw new ModelException( "Invalid Callback given to find modifiers." );
				}
			}
		}

		if ( !is_null( $param ) )
		{
			// Check if paramert 1 is a valid callback and not a string.
			// Strings as function callback are not possible because
			// the user might want to search by key like:
			// Model::find( 'key', 'type' );
			if ( is_callable( $param ) && !is_string( $param ) ) 
			{
				call_user_func_array( $param, array( &$query ) );
			}
			// When no param 2 isset we try to find the record by primary key
			elseif ( is_null( $param2 ) ) 
			{
				$query->where( $settings['table'].'.'.$settings['primary_key'], $param )
					->limit(1);
			}
			// When param one and two isset we try to find the record by
			// the given key and value.
			elseif ( !is_null( $param2 ) )
			{
				$query->where( $param, $param2 )
					->limit(1);
			}
		}

		// alway group the result
		$query->forward_key( $settings['primary_key'] );

		// and we have to fetch assoc
		$query->fetch_arguments = array( 'assoc' );

		// and assign
		return static::assign( $query->run() );
	}
public static function find( $param = null, $param2 = null ) 
	{
		$settings = static::_model();

		$query = DB::select( $settings['table'] );

		// Do we have a find modifier?
		if ( !is_null( $settings['find_modifier'] ) ) 
		{
			$callbacks = $settings['find_modifier'];

			if ( !\CCArr::is_collection( $callbacks ) )
			{
				$callbacks = array( $callbacks );
			}

			foreach( $callbacks as $call )
			{
				if ( is_callable( $call ) ) 
				{
					call_user_func_array( $call, array( &$query ) );
				}
				else 
				{
					throw new ModelException( "Invalid Callback given to find modifiers." );
				}
			}
		}

		if ( !is_null( $param ) )
		{
			// Check if paramert 1 is a valid callback and not a string.
			// Strings as function callback are not possible because
			// the user might want to search by key like:
			// Model::find( 'key', 'type' );
			if ( is_callable( $param ) && !is_string( $param ) ) 
			{
				call_user_func_array( $param, array( &$query ) );
			}
			// When no param 2 isset we try to find the record by primary key
			elseif ( is_null( $param2 ) ) 
			{
				$query->where( $settings['table'].'.'.$settings['primary_key'], $param )
					->limit(1);
			}
			// When param one and two isset we try to find the record by
			// the given key and value.
			elseif ( !is_null( $param2 ) )
			{
				$query->where( $param, $param2 )
					->limit(1);
			}
		}

		// alway group the result
		$query->forward_key( $settings['primary_key'] );

		// and we have to fetch assoc
		$query->fetch_arguments = array( 'assoc' );

		// and assign
		return static::assign( $query->run() );
	}
public static function find ( $ param = null , $ param2 = null ) { $ settings = static :: _model ( ) ; $ query = DB :: select ( $ settings [ 'table' ] ) ; // Do we have a find modifier? if ( ! is_null ( $ settings [ 'find_modifier' ] ) ) { $ callbacks = $ settings [ 'find_modifier' ] ; if ( ! \ CCArr :: is_collection ( $ callbacks ) ) { $ callbacks = array ( $ callbacks ) ; } foreach ( $ callbacks as $ call ) { if ( is_callable ( $ call ) ) { call_user_func_array ( $ call , array ( & $ query ) ) ; } else { throw new ModelException ( "Invalid Callback given to find modifiers." ) ; } } } if ( ! is_null ( $ param ) ) { // Check if paramert 1 is a valid callback and not a string. // Strings as function callback are not possible because // the user might want to search by key like: // Model::find( 'key', 'type' ); if ( is_callable ( $ param ) && ! is_string ( $ param ) ) { call_user_func_array ( $ param , array ( & $ query ) ) ; } // When no param 2 isset we try to find the record by primary key elseif ( is_null ( $ param2 ) ) { $ query -> where ( $ settings [ 'table' ] . '.' . $ settings [ 'primary_key' ] , $ param ) -> limit ( 1 ) ; } // When param one and two isset we try to find the record by // the given key and value. elseif ( ! is_null ( $ param2 ) ) { $ query -> where ( $ param , $ param2 ) -> limit ( 1 ) ; } } // alway group the result $ query -> forward_key ( $ settings [ 'primary_key' ] ) ; // and we have to fetch assoc $ query -> fetch_arguments = array ( 'assoc' ) ; // and assign return static :: assign ( $ query -> run ( ) ) ; }
Model finder
This function allows you direct access to your records.

@param mixed		$param
@param mixed		$param2
@return CCModel
Model finder This function allows you direct access to your records .