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.

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

How to access controller method within loop through in many_many relation?


Go to End


448 Views

Avatar
VPull

Community Member, 58 Posts

3 August 2017 at 7:40pm

Hi all,
I am having an issue to access some method from controller class within loop through.
This is what I am doing

class SamplePage extends Page {

	private static $has_many = array(

		'SampleDataList' => 'SampleData'		

	);

}



class SampleData extend DataObject {

	private static $db = array();

	private static $has_one = array(
		
		'SamplePage' => 'SamplePage'

	);

	private static $many_many = (
	
		'OtherPages' => 'OtherPage'
		
	);

}



class OtherPage extend SiteTree {

	private static $belongs_many_many = array(
		'SampleDatas' => 'SampleData'
	);


}

class OtherPage_Controller extends Page_Controller {


	public function SomeMethod() {
		
	}

}

in template created for 'SampleData' (dataobject as page)

<% loop $OtherPages %> <% end_loop %> I can able to access Title, Content etc. of OtherPage.

But how do I access SomeMethod()