Skip to content

Issue on extending-modx/xpdo/class-reference/xpdoobject/state-accessors/isdirty #559

@shokupanjamin

Description

@shokupanjamin

Affected page(s)

https://docs.modx.com/current/en/extending-modx/xpdo/class-reference/xpdoobject/state-accessors/isdirty

https://github.com/modxorg/Docs/blob/3.x/en/extending-modx/xpdo/class-reference/xpdoobject/state-accessors/isdirty.md

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions