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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   5799 Views

Avatar
SilverRay

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

Thanks!

Avatar
saimo

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.

Avatar
SilverRay

Community Member, 167 Posts

20 January 2008 at 2:14pm

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

Go to Top