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.

All other Modules /

Discuss all other Modules here.

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

Code needs updating


Go to End
Reply


9 Posts   1399 Views

Avatar
jseth

Community Member, 98 Posts

23 October 2010 at 7:49am

When I was using version 2.3.8, I created a News & Events holder and page type using the silverstripe tutorial #2, but I've since upgraded to version 2.4.2, and the page type doesn't work anymore (althought the holder does) - I'm sure it's a simple change of the code but I don't know what to change. Can someone identify what I need to change in the NewsEventsPage.php code below to make it compatible with v2.4.2? Thank you.

<?php
/**
* Defines the NewsEventsPage page type
*/
class NewsEventsPage extends Page {
static $db = array(
'Date' => 'Date',
'Author' => 'Text',
'NewsFooter' => 'Text'
);
static $has_one = array(
);
static $icon = "themes/easternpublic/treeicons/news";

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

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

}

class NewsEventsPage_Controller extends Page_Controller {

}
?>

Avatar
UncleCheese

Forum Moderator, 4096 Posts

23 October 2010 at 8:07am

I'd like to help, but what does "doesn't work anymore" mean?

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
jseth

Community Member, 98 Posts

23 October 2010 at 8:36am

Edited: 23/10/2010 8:39am

Sorry! Before I upgraded from version 2.3.8, when I would click on a NewsEventsPage Type in the CMS, it would open so I could edit it. I've upgraded to 2.4.2 and I guess the code is out of date. Now when I click on an existing NewsEventsPage in the CMS to attempt to edit it, I get a blank box with the heading "The page at http://www.eastech.org says" with an exclamation point in a yellow triangle, and an OK button, but no message. Then a red "Error opening page" message at the status bar at the bottom of the CMS. I'm sure that my code is old (it opened and worked fine in version 2.3.8) I had used the Silverstripe tutorial #2 to create the page holder and type. Can you identify anything in the code that would cause it to fail with version 2.4.2? Thanks so much!

Avatar
UncleCheese

Forum Moderator, 4096 Posts

23 October 2010 at 9:07am

Well always make sure to put your site in dev mode so you can see the errors.

Director::set_environment_type('dev');

If I had to guess at what the problem might be, however, I'd say it's that you're using a CalendarDateField, and that doesn't exist anymore.

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
jseth

Community Member, 98 Posts

24 October 2010 at 4:10am

I tried putting Director::set_environment_type('dev'); in my _config.php but it didn't do anything. No errors displayed. Actually the pages display correctly in the browser except no dates appear, they only will not open in the CMS.

I changed:
'Date' => 'Date',
to
'Date' => 'DateField',

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

then also tried

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

then did dev\build but still get error loading page. I've also tried removing the Date references completely and tried to create a new page (after a dev/build) but that didn't work either.

On the main NewsEventsHolder page the dates aren't showing either, although I don't have an error opening it for editing. Is it a remnant in the database that would cause the error?

Thanks for you help.

Avatar
UncleCheese

Forum Moderator, 4096 Posts

24 October 2010 at 4:29am

This is not valid:

'Date' => 'DateField',

There is no such data type as "DateField". Just "Date" will suffice.

---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

Avatar
jseth

Community Member, 98 Posts

26 October 2010 at 2:53am

Hi Uncle Cheese,
I changed the code to read:

<?php
/**
* Defines the NewsEventsPage page type
*/
class NewsEventsPage extends Page {
static $db = array(
'Date' => 'Date',
'Author' => 'Text',
'NewsFooter' => 'Text'
);
static $has_one = array(
);
static $icon = "themes/easternpublic/treeicons/news";

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

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

return $fields;
}

}

class NewsEventsPage_Controller extends Page_Controller {

}
?>

however, it still won't load in the CMS. It seems not to like the additional fields in the CMS that I added for the NewsEventsPage type, but after that thought, I'm stuck.

Avatar
jseth

Community Member, 98 Posts

27 October 2010 at 8:50am

Uncle Cheese, have you given up?

Go to Top