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.

Form Questions /

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

'getviewer' does not exist on 'DataObjectSet'


Go to End


2 Posts   1458 Views

Avatar
LisaB

Community Member, 28 Posts

19 May 2011 at 6:26am

Hi all,

I have a form consisting of several dropdowns which allows users to filter a list of dataobjects (habits) that they want to see by various fields (deadline, assigned staffmember, priority). This works okay in the page.

The form's action is a function that uses the dropdown selections to create a filter statement for a dataobject::get. So far so good - I can see from my debug statements that the appropriate data object set is got.

I use a foreach loop to iterate over this set, adding some additional bits to each record via an array which seems to work okay. This is then written back into a data object set to be returned and displayed (on the same page as the original form). But I get an error:

'getviewer' does not exist on 'DataObjectSet'

Can anyone help me out with this? Although I have other forms doing a similar thing, I cannot get this to display the list of data objects I am returning. My code is here: http://www.sspaste.com/paste/show/4dd4134046e3c

As always any help much appreciated.

Avatar
Plato Creative

Community Member, 26 Posts

19 May 2011 at 1:08pm

Hi Lisa,

As I explained on the IRC channel, getViewer is on the controller. You're trying to render a set as a page, to which it cannot do. You need to return a controller, which is usually $this.

In shorthand you can simply return an array to customise the template variables available to SSViewer on this controller, so you'll just need to encapsulate your DataObjectSet as such:

return array('HabitSet'=>$habitDisplaySet);

In your templates you can use $habitFilterForm to render the form, then <% control HabitSet %> to process the results.

You can just do this in the plain template (as HabitSet won't exist on normal render and be ignored), or you can create a template WhateverYourClassNameIs_filterhabits.ss (ClassName_action.ss) if you want to jazz things up once you have some results.