Snippets » Database Retrievals
17
Feb
2
Database Configuration Management
Submitted by Hamish Campbell
Wouldn't it be easy to have a single environment configuration for all your SilverStripe sites without having to reconfigure each one individually? Wouldn't it be great not to have to change environment settings when you push your site from development to live servers? This is easy to achieve using the SilverStripe "ConfigureFromEnv" script.
To set this up, remove your $databaseConfig line from your site _config.php and add:
mysite/_config.php
Then create a new _ss_environment.php file. This can live in your web root, in it's parent or it's parent parent folder. Define the following constants:
Read More >>25
May
1
Displaying Fields From a Set of Pages on Another Page
Although ultimately requiring very little code, displaying data from a set of pages on another page can seem confusing for those new to SilverStripe. This example will display all of the Images from all the staff pages on our current page. This works by first returning all the staff pages to our template and cycling through each of them, drawing the Image for each one.
Add the following function to your current pages Controller:
Then inside your template you can simply cycle through the results using <% control GetStaffPages %> like so:
Read More >>
14
May
2
Using @import in your _config.php for Live site Database Details
Have you ever mistakenly overwritten your live site _config.php with your local one? Even if you haven't it can be a pain to keep copying new lines from your local config file to the live one. This little trick means you won't ever have to worry about it again!
First create a file on your live server with the relevant Database info:
mysite/_liveConfig.php
then simply add this line to the bottom of your regular _config.php file:
mysite/_config.php
The @ infront of the include allows it to fail silently when the file does not exist (i.e. on your local server). You can now upload your _config.php file as much as you like without interfering with the live database settings!
Read More >>14
Apr
0
getting objects from multiple child pages
When you want to create a DataObjectSet encompasing objects from all the current pages children you can do something like this:
The first line creates an array of the ID's from all, with the current page and any descendant page ID's.
The second line onwards then gets all Objects that have an ObjectPageID that is either the current page's ID, or any child page of the current page.
You can then add the usual filter, join or limit clauses to the DataObject::get call.
Read More >>