Ah-Ha! That's it!
So, it's not a bug in the code, it's a poorly written doc with an incomplete example.
For anyone else who stumbles on this, this works:
<?php
class Page extends SiteTree {
private static $db = array(
);
private static $has_one = array(
'MyImg' => 'Image'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new UploadField('MyImg'), 'Content');
return $fields;
}
}
class Page_Controller extends ContentController {
private static $allowed_actions = array (
);
public function init() {
$MyVar = $this->MyImg()->getURL();
parent::init();
Requirements::customCSS(<<<CSS
.test {
background-image: url($MyVar);
}
CSS
);
}
}
Thanks, everyone for your help! Much, much appreciated.
Chris