Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

17480 Posts in 4474 Topics by 1973 members

Archive

SilverStripe Forums » Archive » Need help with homepage function

Our old forums are still available as a read-only archive.

Page: 1
Go to End
Author Topic: Need help with homepage function 294 Views
  • NickJacobs
    avatar
    Community Member
    93 posts

    Need help with homepage function Link to this post

    Hi, I'm pretty new to this and having some trouble implementing a function on the homepage which lists pages from another section. I've got the news list sorted from the tutorials but can't seem to replicate it ... and trying to find documentation is a nightmare!

    I've got a DocumentHolder type and a DocumentPage type:

    *** in DocumentHolder.php ***

    class DocumentHolder extends Page {   
       static $db = array();   
       static $has_one = array();
    static $allowed_children = array('DocumentPage');
    }

    class DocumentHolder_Controller extends Page_Controller {}

    *** in DocumentPage.php ***

    class DocumentPage extends Page {
    static $db = array(
    'PDFdocDesc' => 'Text',
    'ShowOnHomePage' => 'Text'
    );
    static $has_one = array(
    'PDFdoc' => 'File'
    );
       
    function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab("Root.Content.Main", new TextField('PDFdocDesc',"Document Description"));
       $fields->addFieldToTab("Root.Content.Main", new FileIFrameField('PDFdoc',"PDF Document"));    
          $fields->addFieldToTab("Root.Content.Main", new CheckboxField('ShowOnHomePage',"Show this on homepage?"));    
          $fields->removeFieldFromTab("Root.Content.Main", "Content");
                
    return $fields;
    }
    }

    class DocumentPage_Controller extends Page_Controller {
       
    }

    and, I'm pretty sure this is where I'm getting trouble because I just copied the news one & I don't fully understand it yet

    class HomePage_Controller extends ContentController {
       function init() {
          parent::init();
          
          }
          
       function LatestNews($num=5) {
       $news = DataObject::get_one("NewsIntroPage");
       return ($news) ? DataObject::get("NewsArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
    }

       function HomeDocs($num=5) {
        $doccys = DataObject::get_one("DocumentHolder");
        return ($doccys) ? DataObject::get("DocumentPage", "ParentID = $doccys->ID", "Date DESC", "", $num) : false;
    }
    }

    In my sidebar I'm trying to do this:

    <% control HomeDocs %>
           <% if $ShowOnHomePage %>   
    <li ><a href="$PDFdoc.filename" target="_blank" title="Download this file">$Title t</a></li>
          <% end_if %>
       <% end_control %>

    any help with this would be much appreciated. Thanks

    294 Views
Page: 1
Go to Top

Currently Online: Webdoc, _Vince

Welcome to our latest member: AlfonsoGrondo

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

Comments on this website? Please give feedback.