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:

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

FirstParagraph/LimitWordCount not working in custom DataObjectSet


Go to End


3 Posts   870 Views

Avatar
digibrains

Community Member, 130 Posts

27 October 2011 at 5:20am

Edited: 27/10/2011 5:22am

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

Forum Moderator, 1899 Posts

27 October 2011 at 8:53pm

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
digibrains

Community Member, 130 Posts

29 October 2011 at 5:04am

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