Class CRUD
Implements interfaces:
- Iterator (internal interface)
Database abstraction layer implementing CRUD procedures
Located in /class.crud.php (line 23)
| Class | Description |
|---|---|
| Model | The model class of the MVC architecture. Extends the CRUD database abstraction layer to enhance it. This class should not be used directly. It should be extended with methods specific to the database table it is interacting with. |
The constructor makes the necessary connection to the database (see Database::Construct) and attempts to load the schema of the specified table.
If the second argument of oData is supplied, the constructor will attempt to load that data into the class for later saving.
If there is a define defined called ENABLE_SCHEMA_CACHING, schema caching is turned on, allowing for faster subsequent page loads.
- string $sTableName: The name of the database table
- mixed $oData: An array or object of data to load into the CRUD object
- Model::__construct() : The Model's constructor - accepts the name of the table and an optional set of data to load into the parent CRUD object. Invokes CRUD::__construct() and passes these two parameters along.
Returns the data currently stored in the CRUD object as a JSON (JavaScript object notation) string. If bIncludeReferences is true, then each reference to the table is considered and added to the XML document.
- bool $bIncludeReferences: Optional; Toggles whether references/relationships should be stored in the JSON string. Default: false
Returns the data currently stored in the CRUD object a well formed XML document as a SimpleXMLElement object. This method requires the SimpleXML extension of PHP to be installed. If the SimpleXML extension is not installed, this method will throw an exception.
- bool $bIncludereferences: Optional; Should this returned XML include references? Default false.
- bool $bProvideAll: Optional; Should this returned XML include all records returned by the last Find() call? If not, only the current record stored is returned. Default false.
- $bIncludeReferences
Returns the data currently stored in the CRUD object a well formed XML document as a string representation. This requires the DOM and SimpleXML extensions of PHP to be installed. If either extension is not installed, this method will throw an exception.
- bool $bIncludeReferences: Optional; Should this returned XML include references? Default false.
- bool $bProvideAll: Optional; Should this returned XML include all records returned by the last Find() call? If not, only the current record stored is returned. Default false.
Helper method for generating a WHERE clause for a query string. WHERE clause is built by supplied keys and associated data
- array $keys: The keys of the dataset
- object $dataSet: The dataset containing data for the WHERE clause
Removes all data and related data from the data array to prepare for the next load.
Prevents stale data from persisting when null values are encountered in the column of the next data set.
Gets the number of rows returned by the last Find() call. If Find() has not yet been called, this method will return This method is invoked through the __call() method to allow using the method name Count(), which is a reserved word in PHP.
Returns the current object from the DataSet generated from the last call to Find().
This method is part of the PHP Iterator implementation
- Iterator::current
Destroys (deletes) the current data. This method will delete the primary record (assuming that the primary key for the data is set).
- Model::Destroy() : Wraps CRUD's Destroy() method to invoke the event OnBeforeDestroy() before calling CRUD::Destroy(), and to invoke the event OnAfterDestroy() afterwards. If either event returns false, execution of this method will stop and false will be returned.
This method will delete records from the table based on column value using the supplied column name (which may have had underscores removed and be cased differently) and column value.
This method is invoked through __call() when the user uses the CRUD::destroyBy[column]() "virtual" method.
- string $sColumn: The name of the column we are basing our delete from. This name may underscores removed and be cased differently
- string $sValue: The value of the column in the first argument that determines which records will be deleted.
This method attempts to load a record from the database based on the passed ID, or a passed set of SQL query clauses. This method can be used retrieve one record from the database, or a set of records that can be iterated through.
- mixed $xId: The ID of the data being found
- array $aClauses: Additional databases clauses, including: join, where, order, offset and limit. All except for join are string that are directly appended to the query. Join is an array of referenced tables to inner join.
This method returns the number of records that match a passed set of SQL query clauses.
This method is very similiar to Find(), except that it returns an integer value representing the number of matching records.
- array $aClauses: Additional databases clauses, including: join and where. Where is a string that are directly appended to the query. Join is an array of referenced tables to inner join.
Attempts to find a relationship to the current database table by the relationship name provided.
- string $sName: The name of the relationship to find
Attempts to find a relationship between two specified tables based on the column they are related through.
- string $sPrimaryTableName: The name of the main table of the relationship
- string $sRelatedTable: The name of the related table of the relationship
- string $sThroughColumn: The name of the column of the primary table that the the related table is related through.
- $sPrimaryTable
Returns an array containing all data stored in the current data set from the last query
This method will retrieve records from the table based on column value using the supplied column name (which may have had underscores removed and be cased differently) and column value.
This method is invoked through __call() when the user uses the CRUD::FindBy[column]() "virtual" method.
- string $sColumn: The name of the column we are pulling records by. This name may underscores removed and be cased differently
- string $sValue: The value of the column in the first argument that determines which records will be selected
- string $sOrder: Optional; The order clause for the query
Loops all data stored within this CRUD class and returns a standard class copy of the data as a StdClass.
NOTE: GetRecord() will move the internal pointers of all 1-M iterators loaded
Returns the table name associated with this CRUD object
Builds an insert query based on the data stored within this CRUD class and executes it against the database.
Determines whether or not there is currently data in the CRUD object. Data is loaded into CRUD through the Find() method, through specifying data into fields manually, or by passing data to the constructor. If any of these cases are met, this method will return true.
Gets the key of the current element in the dataset
- Iterator::key
Loads the specified data (either an array or object) into the CRUD object. This array/object to load can contained referenced data (through foreign keys) as either an array or object.
- mixed $oRecord: The data to load into the CRUD object
Move to the next element in the dataset
- Iterator::next
Grabs all columns for this table and adds each as a key in the data array for this object
Determines if the data currently stored within this CRUD class already exists in the database based on primary key data. This method is used to determine whether to perform an INSERT or UPDATE operation on a table with compound primary keys
Returns to the first element in the dataset
- Iterator::rewind
Based on presence of primary key data, either creates a new record, or updates theexisting record
- Model::Save() : Wraps CRUD's Save() method to invoke the events ValidateUpdate(), Validate(), OnBeforeUpdate(), OnBeforeSave(), respectively, before calling CRUD::Save() for an UPDATE query. Likewise, invokes the events ValidateInsert(), Validate(), OnBeforeInsert() and OnBeforeSave(), respectively, before calling CRUD::Save() for an INSERT statement.
SaveAll() is misleading and really means SaveDeep(). This method will attempt to save all of the data stored within this CRUD class, and calls SaveAll() on all dependent CRUD data that is currently loaded into the class.
- Model::SaveAll() : This method does the same thing as Save(), but also saves all related data loaded into the CRUD object as well. See CRUD::SaveAll() for more details
Responsible for updating the currently stored data for primary table and all foreign tables referenced
Called by the Update() method to generate an update query for this table
Checks if the iterator is valid
- Iterator::valid
Supports several "virtual" or magic methods, such as data manipulation/retrieval through getBy[column_name] and destroyBy[column_name], reserved word methods, such as empty(), and also provides access to public methods of the database, which fakes database class inheritance (which is needed to support multiple database drivers).
- string $sName: The name of the argument to be called magically
- array $aArguments: An array of arguments to pass to the magically called method
Assists slightly in object cloning. If this table has a single primary key, the value of this key will be whiped out when cloning.
Retrieves the specified attribute based on its name and presence in the data array
- string $sName: The name of the attribute to retrieve
Determines if the specified attribute is defined in the data array.
- string $sName: The name of the attribute we are searching for
Attempts to set the value of a database column, or sets a relationship through the CRUD->[column_name] syntax.
- string $sName: The name of the column to set
- string $sValue: The value to set the column specified in the first argument
Creates a readable, string representation of the object using print_r and returns that string.
Unsets the value of a database column. This will effectively remove the column from the known list of columns for this instance, causing a CRUD::Save() operation to not update the value.
- string $sName: The name of the database column to unset
Documentation generated on Thu, 25 Feb 2010 15:59:39 -0500 by phpDocumentor 1.4.3

