I'm trying to filter data objects to display on the front-end of my home page. I created three functions within my HomePage controller to filter categories. However nothing is displaying on the frontend. My code below:
Resource.php:
class Resource extends DataObject {
static $db = array (
'Name' => 'Text',
'FileName' => 'Text',
'Category' => "Enum('Program Details, Photograph Collections, Videos')"
);
public static $has_one = array(
'MyPage' => 'HomePage'
);
public function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'Name', 'Name' ) );
$fields->push( new TextField( 'FileName', 'File Name' ) );
$fields->push( new DropdownField('Category','Category', singleton('Resource')->dbObject('Category')->enumValues()) );
return $fields;
}
Homepage.php:
class HomePage extends Page {
public static $db = array(
);
static $has_many = array (
'Resources' => 'Resource'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$tablefield = new HasManyComplexTableField(
$this,
'Resources',
'Resource',
array(
'Name' => 'Name',
'FileName' => 'File Name',
'Category' => 'Category'
),
'getCMSFields_forPopup'
);
$tablefield->setParentClass('HomePage');
$tablefield->setAddTitle('A Resource');
$fields->addFieldToTab( 'Root.Content.Resources', $tablefield );
return $fields;
}
}
class HomePage_Controller extends Page_Controller {
public function ProgramDetails() {
return $this->Level(1)->Resources("Category = 'Program Details'");
}
public function PhotographCollections() {
return $this->Level(1)->Resources("Category = 'Photograph Collections'");
}
public function Videos() {
return $this->Level(1)->Resources("Category = 'Videos'");
}
}
Homepage.ss:
<% if ProgramDetails %>
<ul>
<% control ProgramDetails %>
<li>$Name</li>
<% end_control %>
</ul>
<% end_if %>
Help!!