I am new to Silverstripe but pretty competent at PHP.
I have set up a test site along the lines of the staff pages tutorial, but have added a new boolean field called Active so that I can hide some entries from public display. Everything is working well in the CMS.
I am stuck working out how to display only the Active (child) records through a template. In mysite/code/ I have this:
PerformerType.php:
<?php
class PerformerType extends Page {
static $allowed_children = array('Performer');
static $db = array(
);
static $has_many = array('Performers' => 'Performer'
);
}
class PerformerType_Controller extends Page_Controller {
function ActivePerformers() {
return DataObject::get('Performer', 'Active');
}
}
?>
Performer.php:
<?php
class Performer extends Page {
static $has_one = array('PerformerType' => 'PerformerType',
'PerformerPhoto' => 'Image'
);
static $defaults = array('Active' => true);
static $db = array('Active' => 'Boolean');
static $singular_name = 'Performer';
static $plural_name = 'Performers';
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', $datefield, 'Content');*/
$fields->addFieldToTab('Root.Content.Main', new CheckboxField('Active', 'Active - will not show if inactive'), 'Content');
$fields->addFieldToTab("Root.Content.Image", new ImageField('PerformerPhoto'));
return $fields;
}
}
class Performer_Controller extends Page_Controller {
}
?>
The ActivePerformers function, when used on a template as a control in templates/mytheme/PerformerType.ss, returns all active Performers, irrespective of category (PerformerType). The Children control correctly returns rows in the relevant category, but ignores the Active field.
Any help much appreciated - I am afraid I have found working my way around the documentation rather frustrating.