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

Articles that only have relations to Other Pages


Go to End


2 Posts   1021 Views

Avatar
Adesso

Community Member, 10 Posts

17 September 2014 at 9:23pm

Edited: 18/09/2014 9:27am

Greetings

as described in Creating Article Pages without Parents I have started making a Article (Review) Page that actually contains no real Published Articles. The Logic is as follow:

ArticleHolder.php

<?php
class ArticleHolder extends Page {
	private static $many_many = array(
		'Articles' => 'Article'
	);
	public function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$allArticles = new GridField(
			'Articles',
			'All Articles',
			$this->Articles(),
			GridFieldConfig_RelationEditor::create()
		);
		$fields->addFieldToTab('Root.Articles', $allArticles);
		return $fields;
	}
}
class ArticleHolder_Controller extends Page_Controller {
	
}

Article.php
<?php
class Article extends DataObject {
	private static $db = array(
		'Heading' => 'Varchar',
		'CreateDate' => 'SS_Datetime',
		'Author' => 'Varchar',
		'Content' => 'HTMLText'
	);
	private static $belongs_many_many = array(
		'Article' => 'ArticleHolder'
	);
	public static $summary_fields = array(
		'Heading' => 'Heading',
		'CreateDate' => 'Date',
		'Author' => 'Author'
	);
	private static $searchable_fields = array(
		'Heading' => 'PartialMatchFilter'
	);
}

so far it works well, but I need some help in parts of the UI.

  • Question: The search result when Linking Articles only show the ID, how do I get the Heading of the result to display?
  • Question/Answer: How do I get Create Date in the edit view to have the 'showcalendar' function
  • Question: Can I create a hidden field for 'lastEditedBy' and save the current user in there on edit
  • Question: How to list a Selection of Pages that this Article Relate to.

I know this is allot of question, but right now I have no clue even how to search for these, and thus ask the more experienced people to help me solve this the right way, from the start.

At least when everybody helps along, the Forum should have some nice examples for all to use;)

PS: Please reply to the relevant Questions in there respective Threads, this way the stuff is all nice and simple to understand.

Greetings from Germany

Avatar
camfindlay

Forum Moderator, 267 Posts

2 October 2014 at 4:26pm

Might be worth checking out this module, possible it does a few of the things you are after: https://github.com/arambalakjian/DataObject-as-Page