Class DataSource
DataSource base class
DataSources are the link between models and the source of data that models represent.
- Object
-
DataSource
Direct known subclasses
DboSourceIndirect known subclasses
Mysql, Postgres, Sqlite, SqlserverCopyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Link: http://book.cakephp.org/2.0/en/models/datasources.html#basic-api-for-datasources
Located at Cake/Model/Datasource/DataSource.php
Method Detail
__constructsource public
__construct( array $config array() )
Constructor.
Parameters
- array
$config
optional array() - Array of configuration information for the datasource.
Overrides
Object::__construct()
_cacheDescriptionsource 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
mixed
mixed
beginsource public
begin( )
Begin a transaction
Returns
boolean
Returns true if a transaction is not in progress
columnsource public
column( string $real )
Converts column types to basic types
Parameters
- string
$real
- Real column type (i.e. "varchar(255)")
Returns
string
Abstract column type (i.e. "string")
commitsource public
commit( )
Commit a transaction
Returns
boolean
Returns true if a transaction is in progress
createsource 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
boolean
success
deletesource 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
boolean
Success
describesource 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|null
Array of Metadata for the $model
enabledsource 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
boolean
Whether or not the Datasources conditions for use are met.
getSchemaNamesource public
getSchemaName( )
Returns the schema name. Override this in subclasses.
Returns
string|null
The schema name
insertQueryDatasource 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
mixed
String of query data with placeholders replaced, or false on failure.
lastAffectedsource public
lastAffected( mixed $source null )
Returns the number of rows affected by last query.
Parameters
- mixed
$source
optional null - The source name.
Returns
integer
Number of rows affected by last query.
lastInsertIdsource public
lastInsertId( mixed $source null )
Returns the ID generated from the previous INSERT operation.
Parameters
- mixed
$source
optional null - The source name.
Returns
mixed
Last ID key generated in previous INSERT
lastNumRowssource public
lastNumRows( mixed $source null )
Returns the number of rows returned by last operation.
Parameters
- mixed
$source
optional null - The source name.
Returns
integer
Number of rows returned by last operation
listSourcessource public
listSources( mixed $data null )
Caches/returns cached results for child instances
Parameters
- mixed
$data
optional null - Unused in this class.
Returns
array|null
Array of sources available in this datasource.
readsource 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
mixed
mixed
resolveKeysource public
resolveKey( Model $Model , string $key )
To-be-overridden in subclasses.
Parameters
-
Model
$Model
- Model instance
- string
$key
- Key name to make
Returns
string
Key name for model.
rollbacksource public
rollback( )
Rollback a transaction
Returns
boolean
Returns true if a transaction is in progress
setConfigsource 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
updatesource 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
boolean
Success
Methods inherited from Object
_mergeVarssource 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.
_setsource 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.
_stopsource 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
dispatchMethodsource 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
mixed
Returns the result of the method call
logsource 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
boolean
Success of log write
requestActionsource 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
mixed
Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
toStringsource public
toString( )
Object-to-string conversion. Each class can override this method as necessary.
Returns
string
The name of this class
Properties summary
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-DataSource.html