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.

Archive

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

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

Sorting Articles


Reply

11 Posts   5151 Views

Avatar
SilverRay

19 January 2008 at 6:18pm Community Member, 167 Posts

> 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!

Avatar
saimo

19 January 2008 at 11:49pm Community Member, 67 Posts

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.

Avatar
SilverRay

20 January 2008 at 2:14pm Community Member, 167 Posts

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