Jump to:

23355 Posts in 17873 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » how to handle thousands of subpages in admin/cms

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

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

Page: 1 2
Go to End
Author Topic: 3400 Views
  • deer421
    Avatar
    Community Member
    8 Posts

    how to handle thousands of subpages in admin/cms Link to this post

    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!

  • ayyurek
    Avatar
    Community Member
    41 Posts

    Re: how to handle thousands of subpages in admin/cms Link to this post

    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.

  • biapar
    Avatar
    Forum Moderator
    435 Posts
  • deer421
    Avatar
    Community Member
    8 Posts

    Re: how to handle thousands of subpages in admin/cms Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: how to handle thousands of subpages in admin/cms Link to this post

    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.

  • deer421
    Avatar
    Community Member
    8 Posts

    Re: how to handle thousands of subpages in admin/cms Link to this post

    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.

  • ayyurek
    Avatar
    Community Member
    41 Posts

    Re: how to handle thousands of subpages in admin/cms Link to this post

    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.

  • deer421
    Avatar
    Community Member
    8 Posts

    Re: how to handle thousands of subpages in admin/cms Link to this post

    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.

    3400 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.