Jump to:

5521 Posts in 1733 Topics by 1220 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Error Saving Content Tutorial 2 Issue with Date field

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

Page: 1 2 3
Go to End
Author Topic: 3597 Views
  • Angelika
    Avatar
    Community Member
    6 Posts

    Error Saving Content Tutorial 2 Issue with Date field Link to this post

    Hello,

    While following Tutorial 2 (http://doc.silverstripe.org/doku.php?id=tutorial:2-extending-a-basic-site) trying to create an Article Page and Article Holder Page. At last step I get an "Error Saving Content" message and the Article Page is never saved.

    Having read through past forum entries I found an interesting point raised by a member (http://silverstripe.org/archive/show/5862#post5862)

    If the Date field is completely left out and we only create an author field then everything works fine. The member suggests that puting the Date field in the static $has_one = array( ) part works. For me this doesn't work and I still get the same error (and yes I have repeatedly tried flushing http://www.sitename.com/dev/build?flush=1). Unfortunately, though many people have raised this issue no one has ever given a solution to the problem.

    Is this a bug or is the code in the tutorial wrong? If the latter, then can someone please change the tutorial as many people (including myself) are spendng hours trying to make it work.

    It may be that I have misunderstood something.

    For your easy reference, the final versions of ArticlePage.php and ArticleHolder.php are as follows:

    -----------------------------
    ArticlePage.php
    -----------------------------

    <?php
    /**
    * Defines the ArticlePage page type
    */
    class ArticlePage extends Page {
    static $db = array(
    'Date' => 'Date',
    'Author' => 'Text'
    );
    static $has_one = array(
    );
    function getCMSFields() {
    $fields = parent::getCMSFields();

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

    return $fields;
    }
    }

    class ArticlePage_Controller extends Page_Controller {

    }

    ?>

    AND

    --------------------------
    ArticleHolder.php
    --------------------------

    <?php
    /**
    * Defines the ArticleHolder page type
    */
    class ArticleHolder extends Page {
    static $db = array(
    );
    static $has_one = array(
    );

    static $allowed_children = array('ArticlePage');
    }

    class ArticleHolder_Controller extends Page_Controller {

    }

    ?>

    I would REALLY REALLY REALLY appreciate it if someone could point out what is going wrong here as I really want to understand this and continue with the site.

  • Angelika
    Avatar
    Community Member
    6 Posts

    Re: Error Saving Content Tutorial 2 Issue with Date field Link to this post

    Hi All,

    I have seen the following error in the error logs:

    PHP Fatal error: Class 'CalendarDateField' not found in /home/sitename/public_html/mysite/code/ArticlePage.php on line 16, referer: http://sitename.com/admin

    Does this error mean that there is no definition in the code for CalendarDateField? Is this not something which is predefined in SS?

    I assume this error is the reason my Article Pages are not working, but I'm still not any closer to decoding this problem. If anyone has any ideas please reply to this post.

    Many Thanks

    Angelika

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Error Saving Content Tutorial 2 Issue with Date field Link to this post

    The tutorial must not have been updated to 2.4 yet. Instead of CalendarDateField you should use DateField.

  • Angelika
    Avatar
    Community Member
    6 Posts

    Re: Error Saving Content Tutorial 2 Issue with Date field Link to this post

    Hi Will,

    many thanks for letting me know! Finally it works!!!

    I have added the solution to my comment on the tutorial so hoepfully if anyone else has the same issue they will pick up the solution from there.

    Thanks

    Angelika

  • Noel
    Avatar
    Community Member
    8 Posts

    Re: Error Saving Content Tutorial 2 Issue with Date field Link to this post

    Tutorial 2 php is still wrong:

    $fields->addFieldToTab('Root.Content.Main', new DateDateField('Date'), 'Content');

    should of course read:

    $fields->addFieldToTab('Root.Content.Main', new DateField('Date'), 'Content');

    I also wasted many hours on this .... can someone at SilverStripe please update the Tutorial perhaps?

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Error Saving Content Tutorial 2 Issue with Date field Link to this post

    can someone at SilverStripe please update the Tutorial perhaps?

    Updated. Note for typos like this the wiki is publicly editable so we welcome typo, spelling fixes from anyone.

  • Noel
    Avatar
    Community Member
    8 Posts

    Re: Error Saving Content Tutorial 2 Issue with Date field Link to this post

    cheers Will.

    My problem now is that I need the ArticleHolder.ss (as per the tutorial) to only display the first 3 Children, not the whole lot.
    Can you suggest an easy way of achieving this?

    - Noel.

  • Dewey
    Avatar
    Community Member
    2 Posts

    Re: Error Saving Content Tutorial 2 Issue with Date field Link to this post

    I'm a noob stuck at tutorial 2 with this problem, local on OSX.

    My ArticlePage.php looks like this:

    <?php
    /**
    * Defines the ArticlePage page type
    */
    class ArticlePage extends Page {
    static $db = array(
    'Date' => 'Date',
    'Author' => 'Text'
    );
       static $has_one = array(
    );
       
       function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date','Artikkel dato (for eksempel: 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 $fields;
    }
       
    }

    class ArticlePage_Controller extends Page_Controller {

    }

    ?>

    If I fill in the datefield in the CMS, the page will not save and firebug reports a 500 error.

    Any suggestions?

    3597 Views
Page: 1 2 3
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.