Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Standard php commands

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

Page: 1
Go to End
Author Topic: 1229 Views
  • Victor
    Avatar
    Community Member
    128 Posts

    Standard php commands Link to this post

    If I used the standard php website then to display the date I would use

    <?php
    date('Y-m-d');
    ?>

    and I would be able to put it on the same page as other php command (f.e. the output of SQL query);

    1) How one can output date (or other standard php command) with SilverStripe?

    2) How one can output them on the same page as output of DataObject::get(....) ?

    3) How to output on the same page two commands of the type: DataObject::get(....) (dealing with different fields of different tables)

    Thank you in advance. Victor

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Standard php commands Link to this post

    Hi Victor

    This is all done inside your controller. You create a punction which returns the data you want and then call it from the template via a <% control functionName %> or simply $Function.

    For your date example you can just use $Now in your template as this is already setup in the content_controller which Page extends.

    You can have as many controller functions as you like and so having multiple peices of data is easy.

    So as an example, if I wanted to list the titles of all the pages on my site I would create a function like this in my Controller:

    public function GetPages(){
    return DataObject::get("Page");
    }

    then in my template I would do this:

    <% control GetPages %>
    <h4>$Title</h4>
    <% end_control %>

    Hope that helps

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Standard php commands Link to this post

    Yes, it really helps!

    Where can I find the description of all built-in functions like $Now ? (thanks for $Now but you help me with understanding was much more helpful)

    Victor

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Standard php commands Link to this post

    You can find a list of all the fields and methods available in the template here:

    http://doc.silverstripe.com/doku.php?id=built-in-page-controls

    However $Now is not on there and I dont think there is a page like that for controller methods, your best bet is to look through the sapphire/core/controller/ContentController.php to see all the functions in there.

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Standard php commands Link to this post

    Thanks! But $Now.nice etc is on this page

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Standard php commands Link to this post

    So it is! Even better

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