I'm looking to allow users to filter the data that is displayed on a page based on a selection they are allowed to make [dropdown lists, check boxes, etc...]
I can't seem to find any examples of how to pull this off.
I know I could make a dataobject like the below
class Staff extends Page {
static $db = array(
'Department' => "Enum('Math,Science','Math')",
'LastName' => 'Text'
);
public static $has_one = array(
);
static $defaults = array (
'ShowInMenus' => false
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new DropdownField(
'Department',
'Select A Department:',
singleton('Staff')->dbObject('Department')->enumValues()
),'Content');
return $fields;
}
}
class Staff_Controller extends Page_Controller {
}
And the use a page type like this to display the Math department
class MathDept extends Page {
static $db = array(
);
static $has_one = array(
);
static $allowed_children = array('Staff');
}
class MathDept_Controller extends Page_Controller {
function DisplayMath(){
$DM = DataObject::get("Staff", "Department = 'Math'", "LastName", null, null);
return $DM;
}
}
And then I could proceed to create a bunch of different page types for each department to display the departments, by changing the filter. Even while I type this I know that must be the most amature way to pull it off... =(
I guess what I need to do is change Math in the where clause to a variable and some how allow the end user (not a CMS user) select the variable they want from from the page and click a "go" button or something of that sort. A live refresh would be in better but I have no idea how to pull this off.
Any help would be greatly appreciated!!