Q: I have some PHP code that I want to run. How do I add it to my page?
A: You will need to add your PHP code to a method on a Controller object. You can't put PHP code directly into templates.
- Each page on your site has a Page Type. Find out the Page Type of the page that you want to add the code to.
- That page type will have a controller class. For example, Page.php contains a class called Page_Controller. Create a method on that Controller object and add your code to this.
- Reference this method inside your template. For example, $MyMethod name or <% control MyMethodName %>
For an example of this, Tutorial 2 shows you how to add latest news to your home page.
Q: How do I insert data into my template?
A: You can insert data into a template by making a method on your controller class that returns the data, and then referencing that method in your template. For an example, see tutorial 2. It shows you how to add latest news to your home page.
If you are trying to insert data into your template that doesn't come from the SilverStripe database, you will need to create ArrayData and DataObjectSet objects. The ArrayData page in the Knowledge Base shows you how to do this.
Q: What's a "Decorator"?
A: A Decorator is a class that plugs into another class and alters its behaviour. SilverStripe projects and modules can provide decorators that change the behaviour of the core application. The most common use of this is for modules to add extra fields to the SilverStripe member database. For more information, see the DataObjectDecorator page in the Knowledge Base.
Q: My code isn't working. How do I debug it?
A: SilverStripe Framework provides a number of debugging tools that can help you work out why your code isn't working. See the debugging page in the Knowledge Base for information about these tools.