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, biapar, Willr, Ingo, swaiba, simon_w

FirstParagraph/LimitWordCount not working in custom DataObjectSet


Reply

3 Posts   510 Views

Avatar
prawnstar

27 October 2011 at 5:20am (Last edited: 27 October 2011 5:22am), Community Member, 116 Posts

When creating a new DataObjectSet, things like FirstParagraph and LimitWordCount don't seem to work with the data from the new Object.

In short, I'm trying to get an object, manipulate the data, create a new object and send that along to the templates.

public function getProducts() {
$products = DataObject::get("Product", "ProductFeature", "", "", "");
$ProductsDataObject = new DataObjectSet();
$multiarray = array();

foreach($products as $product) {
$prodtitle = $product->MenuTitle;
$prodcontent = $product->Content;

...Some other code here...

$proddata = array(
"prodtitle"=>$prodtitle,
"prodcontent"=>$prodcontent,
...other array data here...
);
array_push($multiarray, $proddata);
$ProductsDataObject->push(new ArrayData($proddata));
}
return $ProductsDataObject;
}

In my templates control loop I'm using $prodcontent.FirstParagraph, but getting nothing.

--
Chris

Avatar
swaiba

27 October 2011 at 8:53pm Forum Moderator, 1796 Posts

Tha is because when use "via" the databoject itself it will yeild a DBField type object, but when used in the way above it will yeild a literal string primitive (i think!) - but not the same DBField object. It is the DBField type that contains the methdods.

Avatar
prawnstar

29 October 2011 at 5:04am Community Member, 116 Posts

Thanks swaiba!

Forgive the dumb follow-up question, but...

Instead of creating a new DataObjectSet, is it possible to inject my custom key/values into the DOS that gets returned with the page?

(I'm not sure I'm asking the question correctly. Unfortunately I'm a better php hacker than a php programmer.)

Thanks,
Chris