Snippets - Little bits of code to make you happy
SnippetsA _config.php Cheatsheet
2 July 2010 | | | Supports v2.4Tweet
If your anything like me, you've probably found yourself going through your previous sites looking for that line of code to put in your _config.php file. Well, now you nolonger need to, simply bookmark this page and return to it any time you need to add a line to your config! And if I've missed out anything leave a comment and I'll make sure it gets added :)Continue reading...
SnippetsA Data Object Manager Cheatsheet
6 October 2010 | |Tweet
We all love the DataObject Manager (DOM, not to be confused with the Document Object Model) as well as its creator UncleCheese of LeftAndMain.com. However one thing which has always frustrated me is having to look back through my code or even worse having to search the forums to find that function to set the upload folder, or create a filter for my DOM. So here within this page, lies a comprehensive list of all the things you can do with your DOM and File/ImageDOM. Viva la DOM!Continue reading...
SnippetsOptimizing Complex Models
4 November 2010 | | | Supports v2.4, v2.3Tweet
The SilverStripe ORM engine (Sapphire) makes working with your database a breeze, but that simplicity comes at a cost. Each database query contributes to slower page load times and a complicated data structure can create significant performance issues.
Here are a number of strategies that can be employed to improve your website query performance:Continue reading...
7 October 2010 | | | Supports v2.4, v2.3Tweet
Have you ever found yourself using DataObject::get() to fetch objects in a has_many so that you can filter/sort them easily?
Well as it happens there is no need to do this thanks to a totally undocumented bit of code!Continue reading...
12 March 2010 | | | Supports v2.4, v2.3Tweet
PHP has a very shallow learning curve, it's free and anyone can have a go at making a website by following a few tutorials and implementing their experience with other languages. However, coding for the web can be a risky business, especially with dynamic websites that take some kind of user (or external) input and use that to get data from a database.Continue reading...
16 July 2009 | | | Supports v2.4, v2.3Tweet
Often you will want to manipulate every nth item inside a <% control %> loop. For example say you had a gallery and you wanted every 3rd image to start on a new line, you need to be able to test each item from the template to see if it is divisible by 3 and should therefore have the clear CSS class added to it.Continue reading...
14 April 2009 | | | Supports v2.4, v2.3Tweet
When you want to create a DataObjectSet encompasing objects from all the current pages children you can do something like this
$pageIDs = $this->getDescendantIDList(); $ObjectSet = DataObject::get( "Object", "`ObjectPageID` IN (" . implode(",", $pageIDs) . ")" );Continue reading...
25 May 2009 | | | Supports v2.4, v2.3Tweet
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.Continue reading...