Jump to:

3462 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Getting Error and Returned value with DataObject::get

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

Page: 1
Go to End
Author Topic: 964 Views
  • jdi
    Community Member
    34 Posts

    Getting Error and Returned value with DataObject::get Link to this post

    Hey crew,

    Merry Christmas guys! I hope you've all had a great christmas.

    I have an issue and need some help to resolve something which is in the way of my progression with developing a module:

    public function getRelatedArticles($currentDoc=false) {

             //$currentDoc is a string taken from the URL to define the Article name
             $currentTitle = str_replace('-',' ',$currentDoc);
             $currentArticle = DataObject::get_one('ArticleManagerArticle' , '`Title` = \''.$currentTitle.'\'');

          //'Tags' is part of the DataObject set for each Article

          $QueryTags = explode(" ", $currentArticle->Tags);
          $i = 0;
          $numValues = count($QueryTags);
          $RelatedArticles = new DataObjectSet();
          while($i < $numValues) {
             $QueryTag = '%'.$QueryTags[$i].'%';
             $RelatedArticle = DataObject::get('ArticleManagerArticle','`Title` LIKE \''.$QueryTag.'\'');
          return $RelatedArticles;

    So the 2 things that are occurring here is:

    1. '$currentArticle->Tags' returns the DataObject set value (e.g "Article Important News Story") AND returns this error "[Notice] Trying to get property of non-object", this is because the value $currentTitle doesn't match the DataObject entry 'Title' exactly (it's lower case). But why does it matter!? I'm still getting the value I want to continue to function...?

    2. Can someone assist me with populating my new DataObject inside the while loop? Basically I want to loop to call every article it can related to each word in the 'Tags' string and then let me display them in a template inside

    <% control RelatedArticles %>$Title<% end_control %>

    currently my DataObject $RelatedArticles set isn't being created correctly ?

    Sorry about the big post! Feel free to comment on anything inside the question as any and all solutions or comments are very welcome!


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.