Hi guys,
I’m sure it’s something stupid I’m doing, but I’ve set up a basic plugin which fires onDocPublished.
However, when I try to reference the $modx object, it does not return anything.
Is the object not available for this event, or do I need to reference it in a different way?
My test code basically reads:
file_put_contents(’<path to my root>/test.txt’, $modx->documentObject[’pagetitle’]);
The file is created, but is left empty.
Thanks,
Pete
-
MODX Staff
- 10,725 Posts
You need to specify more information (as requested in red below the input field when you post here in the forums) about what version of MODX you are using, at the very least.
If you are using Evolution, you will have to use a query to get any document info since only the document id is sent to the plugin event.
// invoke OnDocPublished event
$modx->invokeEvent("OnDocPublished",array("docid"=>$id));
Maybe something like this:
<?php
$pagetitle = $modx->db->getValue( $modx->db->select( 'pagetitle', $modx->getFullTableName('site_content'), 'id="'.$docid.'"' ) );
file_put_contents('<path to my root>/test.txt', $pagetitle);
Hi guys.
@Breezer - perfect! Thank you.
@opengeek - apologies. I assumed that, since I was posting under the Evo branch, that would be enough. And, since I wasn’t posting about a bug, it was just a query, that extra info wasn’t necessary. I’ll make sure I post everything next time.
Anyways - all solved.