Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Tutorial 2 problem

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

Page: 1
Go to End
Author Topic: 1526 Views
  • DB_steve
    Avatar
    Community Member
    7 Posts

    Tutorial 2 problem Link to this post

    Experts:

    I am certain this has been discussed before, but I can not find it here. I am just getting started with SS
    and so far Tutorial 1 has been great. Now I get to #2 and things become fuzzy.
    Running on a site on GoDaddy, so all is pre-installed.

    It is not very clear as to where to place the function getCMSFields in the ArticlePage.php code.

    I have placed it 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', new CalendarDateField('Date'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
       
    return $fields;

    }

    class ArticlePage_Controller extends Page_Controller {

    }

    After which I flush and rebuild the db

    http://xxx.com/silverstripe/db/build?flush=1

    After which in the rebuild output I see:

    Parse error: syntax error, unexpected T_CLASS, expecting T_FUNCTION

    Can one of you experts on SS direct me in the right direction please?
    Trying to come up to speed with this and it seems to be a battle to undertand
    how this works in comparison to the build the code by hand method.

    Thanks so much!
    DB_steve

  • Tobbe
    Avatar
    Community Member
    25 Posts

    Re: Tutorial 2 problem Link to this post

    Don't know if you just did a typo, but there is a missing '}' that should end the ArticlePage class.
    So add a } on the line above

    class ArticlePage_Controller extends Page_Controller {

    and it will hopefully work.

  • DB_steve
    Avatar
    Community Member
    7 Posts

    Re: Tutorial 2 problem Link to this post

    Thanks for looking the code over, however the } is there
    just did not get it when I copied the code over to here for posting.

    Now here is what I have discovered.

    If I save this code and do not rebuild the database AND just refresh the CMS
    then create the articleholder page named "news" this works.
    Then create the articlepages insode "news" and this works.

    Now that this has been accomplished, now rebuild the DB and all is ok, no errors
    and the items show up in the draft site as expected.

    Just have to get the flow right, which is not very clear at all in the tutorial.

    db_steve

    <?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 {

    }

    ?>

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Tutorial 2 problem Link to this post

    db_steve - if it helps to clear it up, you need to run db/build?flush=1 (renamed dev/build in version 2.3) whenever you modify anything to do with the database (adding new PHP files, adding new entrys to $db or $has_one etc). dev/build keeps your database and environment up to date

    Whenever you edit anything else (edit templates or add fields to a page) you should always refresh the page or cms with ?flush=1 just to make sure

    1526 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.