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.

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

ajax load - renderWith - DataObjectSet - many_many

Go to End

3 Posts   2345 Views


Community Member, 56 Posts

15 March 2011 at 1:50pm


I have a dropdown field in my frontend and want to load special content via ajax after choosing a Kategorie (category)

Requesting via Ajax works fine... but I dont' know how to bring my valus I get with the DataObject::get() method to my template control snippet,..

that's my sql.. it works fine, (i've tested the sql statement in phpmyadmin. It returns several rows of Typ-Table which I connected to the Kategorie (with the ID 6) via an many_many relationship)

			$doSet = DataObject::get(
				$callerClass = "Kategorie",
				$filter = "Kategorie.ID =6",
				$sort="Typ.Bezeichnung ASC",
				//$sort = "ORDER BY SortOrder DESC",
				$join = "LEFT JOIN Kategorie_Typen ON Kategorie_Typen.KategorieID=Kategorie.ID LEFT JOIN Typ ON Kategorie_Typen.TypID=Typ.ID",
				$limit = ""

now id like to get that DataObject rendered with my Typ-Template
to use it in its control-tag
<% control Typ %>
<% end_control %>

something like that..:

return $doSet->renderWidth(array('TypTemplate'));

this causes two warnings and returns only the empty template:
1. DataObjectSet::__construct:Passed item #0 is not an object or assoziative array, can't properly iterated on in templates
2. Unknown class passed as parameters

How to return my DataObjectSet to my Template and how can I control the data?

Thanks in advance for any advice



Forum Moderator, 5523 Posts

16 March 2011 at 6:21pm

Try call renderWith on the controller instance and adding your set to that

return $this->customize(new ArrayData(array('Typ' => $doSet)))->renderWith(array('TypTemplate'));


Community Member, 56 Posts

17 March 2011 at 4:15am

Hi Willr

First it caused an error: method customize does not exist on 'Produkte_Controller'

so I tried it without the customize method and that works fine now

$data=new ArrayData(array('Typ' => $doSet));
return $data->renderWith(array('TypTemplate'));

Thank s a lot !!