Hello!
I've just done the tutorial for the simple news/blog listings, which is great for what I need. However, instead of putting in a date field, I've used the Created field in the database (which is fine for what I need), but I'm looking to automate the authors name too.
What I'm trying to do, is save the author's ID with a news post, and then when the page is called, pick up the authors name too (so you don't have to input it when you set up the page). I've had a go through $has_one ('Author' => 'Member'), which created an AuthorID field, but I have no idea how to save this. I've tried the following (based on examples I've found online and in the book), but it doesn't work and always saves the value of 0:
function onBeforeWrite() {
parent::onBeforeWrite();
if(!$this->ID) {
$currentMember = Member::currentMember();
if($currentMember) {
$this->AuthorId = $currentMember->ID;
}
}
}
Any help would be massively appreciated :)