Jump to:

23453 Posts in 18902 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » fields available in Page_Controller

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

Page: 1
Go to End
Author Topic: 704 Views
  • bebabeba
    Avatar
    Community Member
    192 Posts

    fields available in Page_Controller Link to this post

    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?

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: fields available in Page_Controller Link to this post

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

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: fields available in Page_Controller Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: fields available in Page_Controller Link to this post

    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)

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: fields available in Page_Controller Link to this post

    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?

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: fields available in Page_Controller Link to this post

    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 %>

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: fields available in Page_Controller Link to this post

    Thanks!the last is the correct solution!!

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