Innoventum.fi
ObjectManager (Single Object)
Basic Concept
Objects extend the ObjectManager, which in turn extends the ObjectModel class. ObjectManager contains the basic methods for loading and saving data.
An object instance requires the following parameters:
* Database Connection($dbc)
* Error Log ($log)
Optional Parameters:
* id (if id is given, the matching row data is automatically loaded from the database.)
* table (defaults to object name, for example for a CarManager the table is 'car')
* key (name of the key field)
Example:
$newsid = 1;
$newsitem = new NewsManager($dbc,$log,$newsid);
echo($newsitem->GetProperty('topic'));
output for a row in the db table 'news' with following contents: id=1, topic='Subject goes here':
Subject goes here
Basic methods
| ->LoadObject($id=NULL, $field="id",$LIMIT=1,$providedStatement=NULL) | loads row matching $id from the database. |
| ->Insert($array) | Inserts the values from the table $array to the object.Field names of array $array must match field names in the database; for $array['name'] a field 'name' must exist in the db table. |
| ->SafeInsert($array) | As Insert, but inserts data in database safe form by executing the mysql_escape_string function for each value. Use this for inserting data from forms! |
| ->GetProperty('nameofproperty') | Get the value of given property |
| ->SetProperty('nameofproperty,$value[,SQL]) | Set the value of given property. Optional parameter SQL states the value is an SQL clause to be executed, for example NOW() |
| ->UnSetProperty('nameofproperty') |
Clear the property value To set NULL value to db (to a field which allows null), use SetProperty with value 'NULL' instead |
| ->Save() | Save the object into the database |
| ->Clear() | Clear object (does not affect values in the database) |
| ->Delete() | Delete the object, also from the database |
| ->GetAttribute('nameofattribute') | Get value of given attribute |
| ->SetAttribute('nameofattribute',$value) | Set value of the attribute |
| ->ClearAttribute('nameofattribute') | delete the attribute |
Attribute does not require a matching field in the object table structure. Using Attributes as query and order parameters is less flexible than with properties. Therefore they are best suited for storing additional information that is not required for the functionality of the object.
Additional methods
| ->CloneObject() | Creates copy of the object: $car2 = $car1->CloneObject; |
| ->TempGetProperty('nameofproperty') | Gets Temporary Property set to the Object |
| ->TempSetProperty('nameofproperty') | Sets Temporary property that is not stored to database when the ->Save() method is called |
| ->SetDbc($dbc) | Sets database connection for the Object. Needed when retrieving object from Session |
| SetLog($log) | Sets error log for the Object. Needed when retrieving object from Session. |
- Creating your own methods
- Example