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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Using ->customise on DataObjectSet?

Go to End

5 Posts   3293 Views


Community Member, 904 Posts

25 February 2008 at 10:19pm


I'm trying to add some custom Fields to a Output generated by the Controller. I tried something like this:

$set = DataObject::get( ... );
return $set->customise( array( 'CustomField' => $myValue ));

This doesn't seem to work though. If i do that, it doesn't preserve the values i got from the DB via DataObject::get().
If i do a foreach loop over the Set and customize every DataObject, it doesn't append the new values:

$set = DataObject::get( ... );
foreach($set as $item){
    $item = $item->customise(array('CustomField' => $myValue));
return $set;

What is the right syntax to customise every DataObject in a DataObjectSet?
Input is much appreciated. Thanks


Community Member, 44 Posts

3 March 2008 at 3:27am

I'm trying to do the exact same thing and can't get it working either!

Just posting to bump the topic and subscribe to the replies ;-)


Community Member, 501 Posts

3 March 2008 at 5:30am

Edited: 03/03/2008 5:33am

I think it might have to be more like this in your foreach loop:

$item = $item->First()->customise(array('CustomField' => $myValue ));

However, I could be wrong though, you could also create a new set to output.

I've only used it in this context so far:

$object= DataObject::get_by_id("Type", $SomeID);
$data = array("Object" => $object);

return $this->customise($data)->renderWith(array("MyPage", "Page"));


Community Member, 44 Posts

3 March 2008 at 10:01am


Thanks for the reply, but doesn't work for me. I get a:
Fatal error: Call to a member function customise() on a non-object

My current example:

$CompanyPageHolder = DataObject::get_one("CompanyPageHolder");
$CompanyPageSet	= DataObject::get("CompanyPage", "ShowInMenus = 1 AND  parentID = $CompanyPageHolder->ID","Sort");
$CustomCompanyPageSet = new DataObjectSet(); //Result dataset
foreach ($CompanyPageSet as $CompanyPageObject) {
	$item = $CompanyPageObject->First()->customise(array('CustomField' => 'Testgin' )); 
	$CustomCompanyPageSet ->merge($item);
return $CustomCompanyPageSet;

This is similar to the example on: for the function BrowserPollResults(). The problem with the example is that it pushes array data into the new set. If I do that, then I have to convert CompanyPageSet to an array and I lose my image data (thumbnail and other company page images) - and only the imageID remains.

Basically I'm looking for a working example of the customize functionality andat the same time keep the dataobject info....


Community Member, 501 Posts

3 March 2008 at 12:02pm

Edited: 03/03/2008 12:04pm

Sorry, my advice for using First() wasn't completely correct I believe and more applicable when you loop through an array-result of groupBy();

What happens when you do:

$CustomCompanyPageSet = new DataObjectSet(); //Result dataset

foreach ($CompanyPageSet as $CompanyPageObject) {

$item = $CompanyPageObject->customise(array('CustomField' => 'Testgin' ));

$CustomCompanyPageSet ->push($item);


That doesn't work? (I haven't done a customise like this to be honest, and maybe it won't work like this, ssadmins?)

You could always still use the arraydata method (like in the tutorial) and pass your object as well as yr new field.

Think that would become something like (in the foreach loop):

$data = array(
"CustomField" => "Testing",
"CompanyPageObject" => $CompanyPageObject
$CustomCompanyPageSet->push(new ArrayData($data));

Of course, then it's not really available in the normal way.