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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Tutorial 2 problem


Go to End


4 Posts   2924 Views

Avatar
DB_steve

Community Member, 7 Posts

14 January 2009 at 6:20am

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

Avatar
Tobbe

Community Member, 25 Posts

14 January 2009 at 6:48am

Edited: 14/01/2009 6:49am

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.

Avatar
DB_steve

Community Member, 7 Posts

14 January 2009 at 6:58am

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 {

}

?>

Avatar
Willr

Forum Moderator, 5523 Posts

14 January 2009 at 5:14pm

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