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.

General Questions

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

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

fields available in Page_Controller


Reply

7 Posts   714 Views

Avatar
bebabeba

22 July 2010 at 10:07pm (Last edited: 22 July 2010 10:08pm), Community Member, 192 Posts

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

22 July 2010 at 11:18pm Forum Moderator, 1796 Posts

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

Avatar
bebabeba

23 July 2010 at 12:35am Community Member, 192 Posts

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

23 July 2010 at 12:40am Forum Moderator, 1796 Posts

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

23 July 2010 at 1:10am Community Member, 192 Posts

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

23 July 2010 at 1:14am Forum Moderator, 1796 Posts

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

23 July 2010 at 4:02am Community Member, 192 Posts

Thanks!the last is the correct solution!!