Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Using Checkboxsetfield values as categories, filtering records


Go to End


3 Posts   1842 Views

Avatar
ayyurek

Community Member, 41 Posts

16 September 2009 at 8:55am

Hi,

I am using checkboxsetfield to categorize items. I manage items with Model Admin.

$categoriesCheckboxSetField = new CheckboxSetField(
   $name = "Category",
   $title = "Please select the related categories for this company",
   $source = array(
      "01" => "Category 01",
      "02" => "Category 02",
   ),
);

Is there a way to get an unordered list of all array values in the template? And filter the result when clicking on the related category?

Kind Regards

Avatar
zenmonkey

Community Member, 545 Posts

17 September 2009 at 12:02pm

Well to get the list of Categories you could do raw SQl query like

$results = DB::query("SELECT DISTINCT Category FROM (insert DataObject Name) ORDER BY Category ASC");

That will get an Array of the Different Categories. Though you'll want/need the Array as a its own DataObject so it'll loop, or you could do a for each $result and run another query like this:

http://www.silverstripe.org/dataobjectmanager-module-forum/show/267505#post267505

Avatar
ayyurek

Community Member, 41 Posts

5 October 2009 at 11:02am

Thank you very much. In the end, I decided to use complex table field.

Here is the link to the post http://www.silverstripe.org/general-questions/show/265149#post265149