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 handle thousands of subpages in admin/cms


Go to End


9 Posts   9735 Views

Avatar
deer421

Community Member, 8 Posts

19 June 2010 at 12:56pm

Edited: 20/06/2010 12:46pm

I recently used SS for a news website. New pages are being added daily. So potentially it will have hundreds or even thousands of subpages under the news categories on the CMS' Page Tree. I am not sure how the SS admin/CMS can handle this. I would like to keep using SS but I would need at least two things in the CMS:

1. To archive/hide certain published subpages to they don't appear on the CMS' Page Tree (otherwise it will be a long list). Of course I will also need a way to view archive or hidden pages. It could be another item under the "Show:" drop down, something like "All pages including archived".

2. When creating a new page, I would like it to appear on the top of the list instead of at the bottom. An option for this in the _config.php will be nice.

Any thoughts on these would be highly appreciated.

Thanks!

Avatar
ayyurek

Community Member, 41 Posts

20 June 2010 at 7:42am

Edited: 20/06/2010 7:44am

Actually you can store newsitems as dataobjects but not pages. It will be easier to manage with DataobjectManager or ModelAdmin.
First install DataObjectsManager module. Then create a NewsHolder.php page in the mysite/code folder.

class NewsHolder extends Page
{
static $has_many = array (
"NewsItems" => "NewsItem"
);

public function getCMSFields()
	{
		$f = parent::getCMSFields();
		$f->addFieldToTab("Root.Content.NewsItems", new DataObjectManager(
			$this,
			'NewsItems',
			'NewsItem',
			array('Title' => 'Title', 'Date' =>'Date'),
			'getCMSFields_forPopup'
		));
		return $f;
	}


}

class NewsHolder_Controller extends Page_Controller {
}

Then create a Dataobject named NewsItem.php in mysite/code folder.

class NewsItem extends DataObject
{
	static $db = array (
		'Title' => 'Text',
		'Date' => 'Date',
		'Content' => 'HTMLText'
	);
	
	static $has_one = array (
		'NewsHolder' => 'NewsHolder',
		'NewsPhoto' => 'Image'
	);
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('Title'),
			new DatePickerField('Date'),
                       	new TextareaField('Content'),
			new FileIFrameField('NewsPhoto')			
			
		);
	}
}

About sorting, you can write your own function inside the NewsHolder_Controller in NewsHolder.php to get the data as you wish.

function SortedNewsItems($num=10) {
	return DataObject::get("NewsItem", "", "Date DESC", "", $num);
    }

Then create a NewsHolder.ss in the theme directory and you can call your sorted newsitems with this code. the number next to control name represents the number of newsitems to be listed. default is 10 as we defined in the function. For pagination you can find the necessary code on forum or silverstripe documentation.

<% control SortedNewsItems(20) %>
<h2>$Title</h2>
<h3>$Date</h3>
<% control NewsImage %><% control ResizedImage(100,50) %><img src="$URL" /><% end_control %><% end_control %>
<p>$Content.FirstParagraph</p>
<p><a href="news-item/$ID">Read More</a></p>

Now you should go and create a NewsDetailPage.php under mysite/code.

class NewsDetailPage extends Page
{	
 
}
class NewsDetailPage_Controller extends Page_Controller {

	}

function NewsDetails() {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
$SQL_start = (int)$_GET['start'];
$where = Convert::raw2SQL(Director::urlParam('ID'));
$doSet = DataObject::get(
$callerClass = "NewsItem",
$filter = "`ID` = '". $where ."'",
$sort = "",
$join = ""
);
return $doSet ? $doSet : false;
}
 
}

The final step is creating the NewsDetailPage.ss template for showing details of the newsitem and creating two pages under the sitetree with page-types of News Holder and News Detail Page. You need only one news detail page and its URL must be "news-item". Or you can rename it in the NewsHolder.ss file, as you wish. You can create as many NewsHolder page as you want, like categories.

<% control SortedNews %>
<h3>$Title</h3>
<h4>$Date</h4>
<p>$NewsImage
$Content</p>
<% end_control %>

I tried to explain with assuming that you are beginner to Silverstripe, sorry if it is not. But anyway I think it will be useful to some other beginners.

Avatar
biapar

Forum Moderator, 435 Posts

20 June 2010 at 8:07am

Good tips.

Avatar
deer421

Community Member, 8 Posts

20 June 2010 at 12:52pm

Thank you ayyurek for the detailed explanation. I appreciate it. But I think I wasn't clear in my original post that I am more concerned about how the *admin/cms* side can handle thousands of subpages. The content editors will not want to see thousands of news items every time they go into a news category on the admin site. I suspect it will be pretty slow as well.

Avatar
Willr

Forum Moderator, 5523 Posts

20 June 2010 at 11:17pm

The content editors will not want to see thousands of news items every time they go into a news category on the admin site. I suspect it will be pretty slow as well.

I think this is what ayyurek was getting at - by making the news items dataobjects then the CMS scales alot better either using complex table fields or model admin. Like you said with a lot of articles managing it in the tree is hard. By using dataobjects you avoid this issue.

Avatar
deer421

Community Member, 8 Posts

21 June 2010 at 1:02am

O yes. My apology. I thought the DataObjectsManager module is for the public site and not the admin/cms. I misunderstood it.

Thanks again ayyurek for the detailed and helpful explanation and example. It is a great solution.

Avatar
ayyurek

Community Member, 41 Posts

21 June 2010 at 3:45am

Edited: 21/06/2010 3:46am

No problem deer421, I just saw your post when I was preparing to write a post about my own problem. So I wrote everything very fast and all together. Maybe that's why you are confused.
The only disadvantage of using DataObjectManager can be that you can not use TinyMCE Editor Field in these popup windows.
If the content of your articles is only text it's not problem but if you need advanced editor features like inserting images, tables etc. it will not be possible. Actually I don't remember if Silverstripe's core complex table fields support Tiny MCE inside or not. If it suports, you can prefer to go with complex tables rather than dataobjectmanager.
By the way, for dataobjects manager there is simplifed html editor field. It provides just some bold, italic, alignment features. In my sample codes, you can just replace TextareaField with SimpleHTMLEditorField.

new SimpleHTMLEditorField('Content'), 

Or you can try ModelAdmin. It's also very flexible.

Avatar
deer421

Community Member, 8 Posts

22 June 2010 at 7:37am

Thank you ayyurek for your help. I need to play around with this to see if it can work for my site. So far the news editors need a wysiwyg editor that allows Arabic text and links creation (internal and external). As you know, those could be done in TinyMCE of the SS Page type. I haven't seen the SimpleHTMLEditorField yet.

Go to Top