Class Model

Description

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.

Located in /class.model.php (line 27)

CRUD
   |
   --Model
Method Summary
Model __construct (string $sTableName, [mixed $oData = null])
bool Destroy ()
bool OnAfterDestroy ()
bool OnAfterInsert ()
bool OnAfterSave ()
bool OnAfterUpdate ()
bool OnBeforeDestroy ()
bool OnBeforeInsert ()
bool OnBeforeSave ()
bool OnBeforeUpdate ()
bool Save ()
bool SaveAll ()
bool Validate ()
bool ValidateInsert ()
bool ValidateUpdate ()
Variables
Methods
Constructor __construct (line 38)

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.

  • access: public
Model __construct (string $sTableName, [mixed $oData = null])
  • string $sTableName: The name of the table to work on
  • mixed $oData: An array or object of data to load into the CRUD object

Redefinition of:
CRUD::__construct()
The constructor makes the necessary connection to the database (see Database::Construct) and attempts to load the schema of the specified table.
Destroy (line 192)

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.

  • return: True if the object can be destroyed, false if not
  • access: public
bool Destroy ()

Redefinition of:
CRUD::Destroy()
Destroys (deletes) the current data. This method will delete the primary record (assuming that the primary key for the data is set).
OnAfterDestroy (line 326)

Triggered after a call to CRUD::Destroy(). If this method returns false, Model::Destroy() will return false. It is up to the user at this point to take the necessary actions, such as rolling back the database transaction.

  • return: True if the object can be destroyed, false if not
  • access: protected
bool OnAfterDestroy ()
OnAfterInsert (line 282)

Triggered after a call to CRUD::Save(), for INSERT only statements only. If this method returns false, Model::Save() will return false. It is up to the user at this point to take the necessary actions, such as Rolling back the database transaction.

  • return: True if the object can be saved, false if not
  • access: protected
bool OnAfterInsert ()
OnAfterSave (line 267)

Triggered after a call to CRUD::Save(), for both INSERT and UPDATE statements only. If this method returns false, Model::Save() will return false. It is up to the user at this point to take the necessary actions, such as Rolling back the database transaction.

  • return: True if the object can be saved, false if not
  • access: protected
bool OnAfterSave ()
OnAfterUpdate (line 297)

Triggered after a call to CRUD::Save(), for UPDATE only statements only. If this method returns false, Model::Save() will return false. It is up to the user at this point to take the necessary actions, such as rolling back the database transaction.

  • return: True if the object can be saved, false if not
  • access: protected
bool OnAfterUpdate ()
OnBeforeDestroy (line 311)

Triggered before a call to CRUD::Destroy(). If this method returns false, Model::Destroy() will be halted and false returned.

  • return: True if the object can be destroyed, false if not
  • access: protected
bool OnBeforeDestroy ()
OnBeforeInsert (line 238)

Triggered before a call to CRUD::Save(), for INSERT statements only. If this method returns false, Model::Save() will be halted and false returned.

  • return: True if the object can be saved, false if not
  • access: protected
bool OnBeforeInsert ()
OnBeforeSave (line 224)

Triggered before a call to CRUD::Save(), for both INSERT and UPDATE actions. If this method returns false, Model::Save() will be halted and false returned.

  • return: True if the object can be saved, false if not
  • access: protected
bool OnBeforeSave ()
OnBeforeUpdate (line 252)

Triggered before a call to CRUD::Save(), for UPDATE statements only. If this method returns false, Model::Save() will be halted and false returned.

  • return: True if the object can be saved, false if not
  • access: protected
bool OnBeforeUpdate ()
Save (line 73)

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.

If any of these events return false, Model::Save() returns false, before calling CRUD::Save().

If CRUD::Save() is invoked and returns true, the events OnAfterUpdate() and OnAfterSave() are invoked, respectively, for UPDATE queries. The events OnAfterInsert() and OnAfterSave() are invoked, respectively, for INSERT queries.

  • return: True if the object can be saved, false if not
  • access: public
bool Save ()

Redefinition of:
CRUD::Save()
Based on presence of primary key data, either creates a new record, or updates theexisting record
SaveAll (line 132)

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

  • return: True if the object can be saved, false if not
  • access: public
bool SaveAll ()

Redefinition of:
CRUD::SaveAll()
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.
Validate (line 340)

Triggered before a call to CRUD::Save(), for both INSERT and UPDATE actions. If this method returns false, Model::Save() will be halted and false returned.

  • return: True if the object can be saved, false if not
  • access: protected
bool Validate ()
ValidateInsert (line 354)

Triggered before a call to CRUD::Save(), for INSERT only. If this method returns false, Model::Save() will be halted and false returned.

  • return: True if the object can be saved, false if not
  • access: protected
bool ValidateInsert ()
ValidateUpdate (line 368)

Triggered before a call to CRUD::Save(), for UPDATE only. If this method returns false, Model::Save() will be halted and false returned.

  • return: True if the object can be saved, false if not
  • access: protected
bool ValidateUpdate ()

Inherited Methods

Inherited From CRUD

CRUD::__construct()
CRUD::AsJSON()
CRUD::AsXML()
CRUD::AsXMLString()
CRUD::buildWhereClause()
CRUD::Cleanup()
CRUD::Count()
CRUD::Current()
CRUD::Destroy()
CRUD::DestroyDataByColumnValue()
CRUD::Find()
CRUD::FindCount()
CRUD::FindRelationship()
CRUD::FindRelationship2()
CRUD::GetAll()
CRUD::GetDataByColumnValue()
CRUD::GetRecord()
CRUD::GetTableName()
CRUD::Insert()
CRUD::IsEmpty()
CRUD::Key()
CRUD::Load()
CRUD::Next()
CRUD::PrepareColumns()
CRUD::RecordExists()
CRUD::Rewind()
CRUD::Save()
CRUD::SaveAll()
CRUD::Update()
CRUD::UpdateQuery()
CRUD::Valid()
CRUD::__call()
CRUD::__clone()
CRUD::__get()
CRUD::__isset()
CRUD::__set()
CRUD::__toString()
CRUD::__unset()

Documentation generated on Thu, 25 Feb 2010 15:59:40 -0500 by phpDocumentor 1.4.3