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.

Customising the CMS /

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

Standard php commands


Go to End


6 Posts   1986 Views

Avatar
Victor

Community Member, 128 Posts

30 March 2009 at 12:19am

Edited: 30/03/2009 12:44am

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

Avatar
Carbon Crayon

Community Member, 598 Posts

30 March 2009 at 1:04am

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

Avatar
Victor

Community Member, 128 Posts

30 March 2009 at 1:46am

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

Avatar
Carbon Crayon

Community Member, 598 Posts

30 March 2009 at 2:09am

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.

Avatar
Victor

Community Member, 128 Posts

1 April 2009 at 2:53am

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

Avatar
Carbon Crayon

Community Member, 598 Posts

1 April 2009 at 3:31am

So it is! Even better :)