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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

News Articles read by members.

Go to End

3 Posts   845 Views


Community Member, 165 Posts

12 June 2009 at 4:40am

I need a way to list a range of news articles so that articles a logged in member has not read show up bold and ones they have read are not bold.

I suppose that this can be done with some sort of database relationship, but I am not sure the best way to do this.

I was thinking of making the News Articles have a static $belongs_many_many relationship to the members but I am not sure how I would set this up so that when a member reads an article it gets put in the belongs_many_many table.

But that is just a guess.


Community Member, 712 Posts

12 June 2009 at 9:58am

You'd modify the "index" method of your article controller. You'd also want a 'has current member read this' method. In this example, I'm assuming that the relation is called "MembersRead" Eg:

function index() {
	if(Member::currentUser() && !$this->HasBeenRead()) {
		$components = $this->MembersRead();

function HasBeenRead() {
		return in_array(array_keys(Member::currentUser()->ID, $this->MembersRead()->getIdList()));			
		return false;

This is untested, but should give you a head start.


Community Member, 165 Posts

13 June 2009 at 3:58am


Thanks for the tip. I was wondering what the index() function is specifically. It seems that it is run when the controller is instantiated just like init() but it must be different.