5099 Posts in 1519 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1125 Views |
-
Standard php commands

30 March 2009 at 12:19am Last edited: 30 March 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
-
Re: Standard php commands

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
-
Re: Standard php commands

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
-
Re: Standard php commands

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.
| 1125 Views | ||
|
Page:
1
|
Go to Top |


