Justin White

Hey everyone, reposting this to general, cause it seems less specific to SS4 and I don’t seem to be getting any love there

I have 2 questions regarding this method I used to create a category field in the CMS for categories of a data object: DropdownField::create( 'MemberCategory', 'Member Categories', array( 'SCO' => 'Senior Counsel', 'JCO' => 'Junior Counsel Over 5 Years', 'JCU' => 'Junior Counsel Under 5 Years', 'BCM' => 'Bar Council Members', 'ASM' => 'Associate Members' ) ), 1) In the template, where I display the category, using $MemberCategory I’m getting the abbreviated name, is there a way to get the full name of that category? 2) How would I filter the Data Objects on the page by these categories?

❤️ (1)
wmk

How is MemberCategory saved to DB? as a Varchar, as a Enum or as a relation?

wmk

IMHO a relation would be the most clean solution. This way you always get a Category Object where you can print the Title etc...

wmk

otherwise you can hardcode the Abbrevation=>Title array somewhere in your class or extension and write a helper method like getCurrentMemberCategoryTitle() { return self::$categories[$this->MemberCategory]; }... And reuse this variable for the dropdown

wmk

This answer was brought to you by http://www.stripecon.eu, the European SilverStripe Conference. See you there 😉

Justin White

Aah stripecon so is that why the main guys are unusually quiet today?

wmk

stripecon is in october, I guess it's just holiday time for some of us

Justin White

Umm the MemberCategory is saved as a varchar, unfortunately, I am also needing the same method to sort other DO’s in another section but by more criteria

Justin White

so either way I’ll need to build a way to filter by data saved in the DB against the DO

wmk

a clean has_one relation is a bit more work beforehand, but you can do much more later on. E.g. get all Members of a Catogory... Category::get()->filter([...])->relation('Members')

Justin White

the other section is documents that need to be filtered by date, location, category and be searched for in a search field, would I be able to use a relation to do all those?

Justin White

essentially follow this: https://www.silverstripe.org/learn/lessons/v4/working-with-data-relationships-many-many-1 ?


Show less replies
mike_henden

hmm, thanks @thats4shaw — on the right track but still getting errors… I’m obviously getting other things wrong!

thats4shaw

I haven’t been following what you are trying to achieve but that error is telling you that you aren’t using the namespaced class for VirtualPage. You’ll need to add

  1. use SilverStripe\CMS\Model\VirtualPage;

👍 (1)
mike_henden

Got it thanks @firesphere — so I’ve renamed back to ProductHolder as that is the page type that it’s copying… and now it’s telling me:

Fatal error: Class 'App\MyProject\VirtualPage' not found in /Users/mikehenden/Sites/Connectors/app/src/VirtualProductHolderPage.php on line 7

So I shouldn’t be using VirtualPage in Line 7?

firesphere

If it could be used for two holder pages, you'll need two separate extends

mike_henden

@firesphere — are you suggesting I ‘extend’ VirtualPage class like so?

(I’ve called it ’VirtualHolderPage as it could be used for two ‘Holder’ types of page)

MichalKleiner

means create an instance of that class and assign to that variable

❤️ (1)
nicolaas

OK = so %$ means "interpret" rather than literal?

firesphere

Tells injector it's a class that should be injected and not just a string