Class DataSource
DataSource base class
DataSources are the link between models and the source of data that models represent.
- CakeObject
- DataSource
Direct Subclasses
Link: http://book.cakephp.org/2.0/en/models/datasources.html#basic-api-for-datasources
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
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 -
close() public
Closes a connection. Override in subclasses. -
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.
-
getSchemaName() public
Returns the schema name. Override this in subclasses. -
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 $conditions = null )
Delete a record(s) in the datasource.
To-be-overridden in subclasses.
Parameters
-
Model
$Model - The model class having record(s) deleted
- mixed $conditions optional null
- The conditions to use for deleting.
Returns
Success
describe() public ¶
describe( Model
|string $model )
Returns a Model description (metadata) or null if none found.
Parameters
-
Model
|string $model - The model to describe.
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.
getSchemaName() public ¶
getSchemaName( )
Returns the schema name. Override this in subclasses.
Returns
The schema name
insertQueryData() public ¶
insertQueryData( string $query , array $data , string $association , Model
$Model , 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.
-
Model
$Model - Model instance.
- array $stack
- The context stack.
Returns
String of query data with placeholders replaced, or false on failure.
lastAffected() public ¶
lastAffected( mixed $source = null )
Returns the number of rows affected by last query.
Parameters
- mixed $source optional null
- The source name.
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
- The source name.
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
- The source name.
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
- Unused in this class.
Returns
Array of sources available in this datasource.
read() public ¶
read( Model
$Model , array $queryData = array() , integer $recursive = null )
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
- integer $recursive optional null
- Number of levels of association
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 , mixed $conditions = 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.
- mixed $conditions optional null
- The array of conditions to use.
Returns
Success
Methods inherited from CakeObject
_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 Hash::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_ERR , null|string|array $scope = null )
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_ERR
- Error type constant. Defined in app/Config/core.php.
- null|string|array $scope optional null
The scope(s) a log message is being created in. See CakeLog::config() for more information on logging scopes.
Returns
Success of log write
requestAction() public ¶
requestAction( string|array $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
- string|array $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( )
CakeObject-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