Jump to:

11002 Posts in 2734 Topics by 1823 members

All other Modules

SilverStripe Forums » All other Modules » Code needs updating

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 1290 Views
  • jseth
    Avatar
    Community Member
    98 Posts

    Code needs updating Link to this post

    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 {

    }
    ?>

  • UncleCheese
    Avatar
    4085 Posts

    Re: Code needs updating Link to this post

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

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

  • jseth
    Avatar
    Community Member
    98 Posts

    Re: Code needs updating Link to this post

    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!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Code needs updating Link to this post

    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

  • jseth
    Avatar
    Community Member
    98 Posts

    Re: Code needs updating Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Code needs updating Link to this post

    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

  • jseth
    Avatar
    Community Member
    98 Posts

    Re: Code needs updating Link to this post

    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.

  • jseth
    Avatar
    Community Member
    98 Posts

    Re: Code needs updating Link to this post

    Uncle Cheese, have you given up?

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