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:

Archive /

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

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

Sorting Articles

Go to End

11 Posts   5584 Views


Community Member, 167 Posts

19 January 2008 at 6:18pm

> 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).



Community Member, 67 Posts

19 January 2008 at 11:49pm

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.


Community Member, 167 Posts

20 January 2008 at 2:14pm

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

Go to Top