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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

fields available in Page_Controller


Go to End


7 Posts   1050 Views

Avatar
bebabeba

Community Member, 193 Posts

22 July 2010 at 10:07pm

Edited: 22/07/2010 10:08pm

Hi!

I create a new page type (ArticlePage.php) with a new field: date. Silverstripe create a new table articlepage in db.

If a call in my ArticlePage.ss the new field $date I can't see the value. Otherwise if a call $Title a see the name of the page. The cause is that Title filed is defined in sitetree table? to see $date i can use a query in ArticlePage.php?

Avatar
swaiba

Forum Moderator, 1899 Posts

22 July 2010 at 11:18pm

could you post the relevant code... I am fairly sure this should work...

Avatar
bebabeba

Community Member, 193 Posts

23 July 2010 at 12:35am

This is my ArticlePage.php

class ArticlePage extends Page {

public static $db = array(
"date" => "Date",
);

And this is my ArticlePage.ss
<div class="dashtop01">
$Title $date
</div>

The first $Title variable is correct and print ArticlePage title. $Date is not correct but in my articlepage table date field is not empty

Avatar
swaiba

Forum Moderator, 1899 Posts

23 July 2010 at 12:40am

maybe it is todo with capitalisation? could you rename your field 'Date' instead? (or if there is a conflict 'ArticleDate'?)

what does $Created get you? (this is another 'core' field)

Avatar
bebabeba

Community Member, 193 Posts

23 July 2010 at 1:10am

I think the problem is not the name but the field. If Ihave a core field like Title I can use $Title in my .ss file. If I have a new field, only for my new page, I can't do that. What do you think? Is this correct?

Avatar
swaiba

Forum Moderator, 1899 Posts

23 July 2010 at 1:14am

Maybe it is because by default you are at 'Page' level/context/control and cannot see your extended fields...

e.g. it is like your template is surrounded with

<% control Page %>
<% end_control %>

How about creating a function in your controller like

function ControlArticlePage()
{
return DataObject::get_by_id('ArticlePage',$this->ID);
}

<% control ControlArticlePage %>
$date
<% end_control %>

Avatar
bebabeba

Community Member, 193 Posts

23 July 2010 at 4:02am

Thanks!the last is the correct solution!!