Closed chrisgwynne closed 6 years ago
Yes, you can use a hook to run your logic for specific events, e.g. did-save-comment
.
c::set('comments.hooks.did-save-comment', function ($comments, $comment) { $page = $page->$parent()->update(array('lastupdated' => 'd-m-Y H:i:s')); return false; });
I'm not the best with this unfortunately florian, keeps throwing up errors.
$page
is undefined in config.php. You can access the page object using the $comment
variable:
c::set('comments.hooks.did-save-comment', function ($comments, $comment, $commentPage) {
try {
$comment->page()->update(...);
} catch (Exception $e) {
// do something with the exception
echo $e->getMessage();
}
});
Some other notes:
$page->$parent()
will never work, the dollar-sign ($) is used only when accessing a variable, not methods and properties: $page->parent()
.'lastupdated' => 'd-m-Y H:i:s'
should be 'lastupdated' => date('d-m-Y H:i:s')
.did-save-comment
hook, as the return value is ignored.Florian, this works perfectly, thank you so much! :)
Is there any way to update a field in the parent page when posting a comment?