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   727 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, 1799 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, 1799 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, 1799 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!!