-
Notifications
You must be signed in to change notification settings - Fork 112
Open
Description
Affected page(s)
What needs to be improved?
The Example provided in the Documentation is incorrect:
$skrewt = $xpdo->getObject('Skrewt',1);
echo $skrewt->isDirty() ? 1 : 0; // prints 0
$skrewt->set('poisonous',false);
echo $skrewt->isDirty() ? 1 : 0; // prints 1
$skrewt->isDirty() requires a string $key parameter to be passed in as per the Syntax / API documentation.
Calling the method without the required $key parameter throws a PHP error.
In the last line of the Example, calling echo $skrewt->isDirty('poisonous') ? 1 : 0; // prints 1 (where $key = 'poisonous') would return the expected result.
There does not appear to be a direct method to check if any field on an object is dirty. However, based on the API, it would be possible to inspect the $object->_dirty property to see if it contains any dirty fields as a workaround.
//Test if Skrewt contains any dirty fields.
if (sizeof($skrewt->_dirty)) {
echo "Skrewt has dirty fields.";
} else {
echo "Skrewt is not dirty.";
}
print_r($skrewt->_dirty); //List the dirty fields.
Relevant context
See also method definition at: core/xpdo/om/xpdoobject.class.php @ Line 2381
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels