Class DataSource
DataSource base class
- Object
- DataSource
Direct Subclasses
Copyright: Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/Model/Datasource/DataSource.php
Properties summary
-
$_baseConfig
protectedarray
The default configuration of a specific DataSource -
$_descriptions
protectedarray
Holds references to descriptions loaded by the DataSource -
$_sources
protectedarray
Holds a list of sources (tables) contained in the DataSource -
$_transactionStarted
protectedboolean
Whether or not this DataSource is in the middle of a transaction -
$cacheSources
publicboolean
Whether or not source data like available tables and schema descriptions should be cached
-
$config
publicarray
The DataSource configuration -
$connected
publicboolean
Are we connected to the DataSource?
Method Summary
-
__construct() public
Constructor. -
__destruct() public
Closes the current datasource. -
_cacheDescription() protected
Cache the DataSource description -
begin() public
Begin a transaction -
column() public
Converts column types to basic types -
commit() public
Commit a transaction -
create() public
Used to create new records. The "C" CRUD. -
delete() public
Delete a record(s) in the datasource. -
describe() public
Returns a Model description (metadata) or null if none found. -
enabled() public
Check whether the conditions for the Datasource being available are satisfied. Often used from connect() to check for support before establishing a connection.
-
insertQueryData() public
Replaces{$__cakeID__$}
and{$__cakeForeignKey__$}
placeholders in query data. -
lastAffected() public
Returns the number of rows affected by last query. -
lastInsertId() public
Returns the ID generated from the previous INSERT operation. -
lastNumRows() public
Returns the number of rows returned by last operation. -
listSources() public
Caches/returns cached results for child instances -
read() public
Used to read records from the Datasource. The "R" in CRUD -
resolveKey() public
To-be-overridden in subclasses. -
rollback() public
Rollback a transaction -
setConfig() public
Sets the configuration for the DataSource. Merges the $config information with the _baseConfig and the existing $config property.
-
update() public
Update a record(s) in the datasource.
Method Detail
__construct() public ¶
__construct( array $config = array() )
Constructor.
Parameters
- array $config optional array()
- Array of configuration information for the datasource.
Overrides
_cacheDescription() protected ¶
_cacheDescription( string $object , mixed $data = null )
Cache the DataSource description
Parameters
- string $object
- The name of the object (model) to cache
- mixed $data optional null
- The description of the model, usually a string or array
Returns
begin() public ¶
begin( )
Begin a transaction
Returns
Returns true if a transaction is not in progress
column() public ¶
column( string $real )
Converts column types to basic types
Parameters
- string $real
- Real column type (i.e. "varchar(255)")
Returns
Abstract column type (i.e. "string")
commit() public ¶
commit( )
Commit a transaction
Returns
Returns true if a transaction is in progress
create() public ¶
create( Model
$model , array $fields = null , array $values = null )
Used to create new records. The "C" CRUD.
To-be-overridden in subclasses.
Parameters
-
Model
$model - The Model to be created.
- array $fields optional null
- An Array of fields to be saved.
- array $values optional null
- An Array of values to save.
Returns
success
delete() public ¶
delete( Model
$model , mixed $id = null )
Delete a record(s) in the datasource.
To-be-overridden in subclasses.
Parameters
-
Model
$model - The model class having record(s) deleted
- mixed $id optional null
- $conditions The conditions to use for deleting.
describe() public ¶
describe( Model
|string $model )
Returns a Model description (metadata) or null if none found.
Parameters
-
Model
|string $model
Returns
Array of Metadata for the $model
enabled() public ¶
enabled( )
Check whether the conditions for the Datasource being available are satisfied. Often used from connect() to check for support before establishing a connection.
Returns
Whether or not the Datasources conditions for use are met.
insertQueryData() public ¶
insertQueryData( string $query , array $data , string $association , array $assocData , Model
$model , Model
$linkModel , array $stack )
Replaces {$__cakeID__$}
and {$__cakeForeignKey__$}
placeholders in query data.
Parameters
- string $query
- Query string needing replacements done.
- array $data
- Array of data with values that will be inserted in placeholders.
- string $association
- Name of association model being replaced
- array $assocData
-
Model
$model - Instance of the model to replace $cakeID$
-
Model
$linkModel - Instance of model to replace $cakeForeignKey$
- array $stack
Returns
String of query data with placeholders replaced.
lastAffected() public ¶
lastAffected( mixed $source = null )
Returns the number of rows affected by last query.
Parameters
- mixed $source optional null
Returns
Number of rows affected by last query.
lastInsertId() public ¶
lastInsertId( mixed $source = null )
Returns the ID generated from the previous INSERT operation.
Parameters
- mixed $source optional null
Returns
Last ID key generated in previous INSERT
lastNumRows() public ¶
lastNumRows( mixed $source = null )
Returns the number of rows returned by last operation.
Parameters
- mixed $source optional null
Returns
Number of rows returned by last operation
listSources() public ¶
listSources( mixed $data = null )
Caches/returns cached results for child instances
Parameters
- mixed $data optional null
Returns
Array of sources available in this datasource.
read() public ¶
read( Model
$model , array $queryData = array() )
Used to read records from the Datasource. The "R" in CRUD
To-be-overridden in subclasses.
Parameters
-
Model
$model - The model being read.
- array $queryData optional array()
- An array of query data used to find the data you want
Returns
resolveKey() public ¶
resolveKey( Model
$model , string $key )
To-be-overridden in subclasses.
Parameters
-
Model
$model - Model instance
- string $key
- Key name to make
Returns
Key name for model.
rollback() public ¶
rollback( )
Rollback a transaction
Returns
Returns true if a transaction is in progress
setConfig() public ¶
setConfig( array $config = array() )
Sets the configuration for the DataSource. Merges the $config information with the _baseConfig and the existing $config property.
Parameters
- array $config optional array()
- The configuration array
update() public ¶
update( Model
$model , array $fields = null , array $values = null )
Update a record(s) in the datasource.
To-be-overridden in subclasses.
Parameters
-
Model
$model - Instance of the model class being updated
- array $fields optional null
- Array of fields to be updated
- array $values optional null
- Array of values to be update $fields to.
Returns
Success
Methods inherited from Object
_mergeVars() protected ¶
_mergeVars( array $properties , string $class , boolean $normalize = true )
Merges this objects $property with the property in $class' definition. This classes value for the property will be merged on top of $class'
This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine this method as an empty function.
Parameters
- array $properties
- The name of the properties to merge.
- string $class
- The class to merge the property with.
- boolean $normalize optional true
- Set to true to run the properties through Set::normalize() before merging.
_set() protected ¶
_set( array $properties = array() )
Allows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
Parameters
- array $properties optional array()
- An associative array containing properties and corresponding values.
_stop() protected ¶
_stop( integer|string $status = 0 )
Stop execution of the current script. Wraps exit() making testing easier.
Parameters
- integer|string $status optional 0
- see http://php.net/exit for values
dispatchMethod() public ¶
dispatchMethod( string $method , array $params = array() )
Calls a method on this object with the given parameters. Provides an OO wrapper
for call_user_func_array
Parameters
- string $method
- Name of the method to call
- array $params optional array()
- Parameter list to use when calling $method
Returns
Returns the result of the method call
log() public ¶
log( string $msg , integer $type = LOG_ERROR )
Convenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
Parameters
- string $msg
- Log message
- integer $type optional LOG_ERROR
- Error type constant. Defined in app/Config/core.php.
Returns
Success of log write
requestAction() public ¶
requestAction( mixed $url , array $extra = array() )
Calls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()
Passing POST and GET data
POST and GET data can be simulated in requestAction. Use $extra['url']
for
GET data. The $extra['data']
parameter allows POST data simulation.
Parameters
- mixed $url
String or array-based url. Unlike other url arrays in CakePHP, this url will not automatically handle passed and named arguments in the $url parameter.
- array $extra optional array()
if array includes the key "return" it sets the AutoRender to true. Can also be used to submit GET/POST data, and named/passed arguments.
Returns
Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
toString() public ¶
toString( )
Object-to-string conversion. Each class can override this method as necessary.
Returns
The name of this class
Properties detail
$_transactionStarted ¶
Whether or not this DataSource is in the middle of a transaction
false
$cacheSources ¶
Whether or not source data like available tables and schema descriptions should be cached
true