Jump to:

22976 Posts in 11620 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Tutorial 2: Issues

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
Go to End
Author Topic: 1070 Views
  • Nath1011
    Avatar
    Community Member
    2 Posts

    Tutorial 2: Issues Link to this post

    Ive been working through tutorial 2 and i can not get author and date fields to work can someone please help.

    ArticlePage.php

    <?php
    /**
    *Defines the ArticlePage page type
    */
    class ArticlePage extends Page {
       static $db = array(
          'Date' => 'Date',
          'Author' => 'Text'
          );
       static $has_one = array(
          );
       static $icon = "themes/tutorial/images/treeicons/news";
       static $defaults = array(
    'ProvideComments' => true
          );
    }

       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date','Article Date (for example: 20/12/2010)'), 'Content');
          $datefield->setConfig('showCalendar', true);
          $dateField->setConfig('dateformat', 'dd/MM/YYYY');
          
          $fields->addFieldToTab('Root.Content.Main', new TextField('Author','Author Name'), 'Content');
          
          return $feilds;
       }
                                                 

    class ArticlePage_Controller extends Page_Controller {
       
    }

    ?>

    ArticlePage.ss

    <% include Menu2 %>
    <div id="Content" class="typography">
    <% include Breadcrumbs %>
    <h1>$Title</h1>
    $Content
    <div class="newsDetails">
    Posted on $Date.Nice by $Author
    </div>
       $PageComments
    </div>

    ArticleHolder.php

    <?php
    /**
    * Defines the ArticleHolder page type
    */
    class ArticleHolder extends Page {
       static $db = array(
                    );
       static $has_one = array(
                         );
       static $icon = "themes/tutorial/images/treeicons/news";
       static $allowed_children = array('ArticlePage');
    }

    class ArticleHolder_Controller extends Page_Controller {
       function rss() {
       $rss = new RSSFeed($this->Children(), $this->Link(), "The coolest news around");
       $rss->outputToBrowser();
       }
       function init() {
       RSSFeed::linkToFeed($this->Link() . "rss");
       parent::init();
       }
    }
    ?>

    ArticleHolder.ss

    <div id="Content" class="typography">
    $Content
    <ul id="NewsList">
    <% control Children %>
    <li class="newsDateTitle"><a href="$Link" title="Read more on &quot;{$Title}&quot;">$Title</a></li>
    <li class="newsDateTitle">$Date.Nice</li>
    <li class="newsSummary">$Content.FirstParagraph <a href="$Link" title="Read more on &quot;{$Title}&quot;">Read more &gt;&gt;</a></li>
    <% end_control %>
    </ul>
    </div>

  • prawnstar
    Avatar
    Community Member
    116 Posts

    Re: Tutorial 2: Issues Link to this post

    Can you describe what exactly isn't working? I.e., expected input, expected outcome.

    I did notice this from looking at your ArticlePage.php file. You show:

    <?php
    /**
    *Defines the ArticlePage page type
    */
    class ArticlePage extends Page {
    static $db = array(
    'Date' => 'Date',
    'Author' => 'Text'
    );
    static $has_one = array(
    );
    static $icon = "themes/tutorial/images/treeicons/news";
    static $defaults = array(
    'ProvideComments' => true
    );
    }

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date','Article Date (for example: 20/12/2010)'), 'Content');
    $datefield->setConfig('showCalendar', true);
    $dateField->setConfig('dateformat', 'dd/MM/YYYY');

    $fields->addFieldToTab('Root.Content.Main', new TextField('Author','Author Name'), 'Content');

    return $feilds;
    }

    class ArticlePage_Controller extends Page_Controller {

    }

    ?>

    Should be:

    <?php
    /**
    * Defines the ArticlePage page type
    */

    class ArticlePage extends Page {
       static $db = array(
          'Date' => 'Date',
          'Author' => 'Text'
       );
       static $has_one = array(
       );
       static $icon = "themes/tutorial/images/treeicons/news";
       static $defaults = array(
          'ProvideComments' => true
       );

       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date','Article Date (for example: 20/12/2010)'), 'Content');
          $datefield->setConfig('showCalendar', true);
          $dateField->setConfig('dateformat', 'dd/MM/YYYY');
          $fields->addFieldToTab('Root.Content.Main', new TextField('Author','Author Name'), 'Content');

          return $feilds;
       }

    }

    class ArticlePage_Controller extends Page_Controller {

    }

    Note, your getCMSField() function should be inside the class.

    1070 Views
Page: 1
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.