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.

Customising the CMS

Error Saving Content Tutorial 2 Issue with Date field


Go to End
Reply

21 Posts   3699 Views

Avatar
Angelika

23 April 2010 at 10:21pm Community Member, 6 Posts

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.

Avatar
Angelika

26 April 2010 at 5:27am Community Member, 6 Posts

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

Avatar
Willr

26 April 2010 at 11:26am Forum Moderator, 5511 Posts

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

Avatar
Angelika

28 April 2010 at 10:49pm Community Member, 6 Posts

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

Avatar
Noel

6 May 2010 at 6:53pm Community Member, 8 Posts

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?

Avatar
Willr

6 May 2010 at 8:13pm Forum Moderator, 5511 Posts

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.

Avatar
Noel

3 June 2010 at 7:03am (Last edited: 3 June 2010 7:05am), Community Member, 8 Posts

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.

Avatar
Dewey

30 May 2011 at 12:51am Community Member, 2 Posts

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?

Go to Top