Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Sorting Articles

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

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

Page: 1 2
Go to End
Author Topic: 5106 Views
  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: Sorting Articles Link to this post

    > Thanks also for indirectly aswering one of my previous questions, how to access fields from
    > php code.

    Can you elaborate a bit on this, because I seem to be missing where this was answered (I'm currently trying to implement something similar).

    Thanks!

  • saimo
    Avatar
    Community Member
    67 Posts

    Re: Sorting Articles Link to this post

    He wrote:
    return DataObject::get("ArticlePage", "ParentID = {$this->ID}", "Created DESC", "", $limit);

    Where $this->ID is the ID field of the current row in the database, so you can access fields using $this->[your_fieldname_here] syntax.

    For example, this is how my current LatestNews looks like:

    function LatestNews($limit = null) {
          if (null == $limit)
             $limit = $this->Limit;
             
          return DataObject::get("ArticlePage", "ParentID = {$this->ID}", "Created DESC", "", $limit);
       }

    I have created an additional field named 'Limit' in the db to make the number of displayed ArticlePages configureable from the CMS, but still overrideable from the templates.

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: Sorting Articles Link to this post

    I see what you mean, thanks for following up on $this ;)

    5106 Views
Page: 1 2
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.