In this section you will find short snippets of code that we have found useful and often hard to uncover.
02
Jul
11
A _config.php Cheatsheet
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 :)
Read More >>12
Jun
0
Customise buttons in userforms module
Submitted by Barry Keenan
I wanted more control over the styling of submit buttons in the userforms module. The standard button use either an <input> tag or a <button> tag. I needed an extra span so I could style the button super pretty, à la:
31
May
0
Customize the Redirect after a successful Member Login
When a Member logs in to /Security/login without a ?BackURL= specified, they are always redirected back to the form with a success message and form without any fields. While this works great to keep the code/form tight, it is a less than ideal use experience. Modifying this behavior is a little tricky as much of the controller and rendering actions are fixed in the Security class. This is further complicated by the use of Director::redirect calls that set response headers when the login form is processed. I find by overriding the form and replacing it with the excellent useCustomClass call works well.
The Problem: Base /Security/login form redirects to itself on success, always tagging ?BackURL=/home looks sort of messy across your site.
The Solution: Make the base MemberLoginForm redirect somewhere useful on success.
Read More >>
23
Apr
7
Controlling the order of CSS includes
Submitted by Matt Clegg
Usually CSS developers are lazy -even more so than php developers! What usually happens is (as you can see in firebug) that styles get redefined by sub CSS files depeding on a parent containing div -so it's important to include these CSS files in the correct order, otherwise they will be overwritten incorrectly and the style wont appear as you wish.
Your probably already using Requirements::themedCSS but there is another function called Requirements::insertHeadTags. This is great for including custom style sheets because you can call it AFTER your usuall CSS. An example would be something like;
Read More >>
15
Apr
2
Automatically ?flush when in 'dev' mode
Submitted by Dan Hensby
Often when doing development work on a website - and particularly the templates - it can be a pain having to remember to add ?flush to the end of the URL to make sure all of your changes have come through.
I'm sure that all of us have had that "d'oh" moment when we have spent too much time wondering why our changes weren't working, only to find a simple flush fixed it.
If you have set up a domain in your set_dev_servers array or added Director::set_environment_type('dev') to your _config.php file then you can also add:
Read More >>
22
Mar
3
Using other systems together with Silverstripe
Submitted by Yuri Goul
Silverstripe uses mod_rewrite to catch all calls to your website in the form of urls and route them to sapphire/main.php. This behavior is implemented with the rules in your .htaccess file in the root of your site. This can become a problem when you want to use other systems together with Silverstripe because you simply can not reach the url of those other systems.
An example: if your want to use phplists as a newsletter system, it is usually installed under yoursite.com/lists. However, under normal circumstances you can not have your visitors reach yoursite.com/lists when using Silverstripe because it is rerouted to sapphire/main.php?url=lists.
Read More >>
12
Mar
2
Securing your site
Submitted by Daniel Hensby
comic from xkcd.com
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.
Old school websites will use an id to get a pages content, eg: www.example.com/index.php?id=3.
This can lead to a few problems if the id is not sanitised before being added to an SQL query.
Read More >>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 >>15
Feb
0
Disable Default JavaScript Behaviours
Submitted by Hamish Campbell
By default SilverStripe uses bulky and sometimes unwanted JavaScript libraries to handle form validation and AJAX page commenting features. Often you want to disable this behaviour so you can integrate your own JavaScript code. This is easily achieved with the following two lines in you site configuration file:
mysite/_config.php
Read More >>
05
Jan
1
Add attachments to Silverstripe Form submissions
Submitted by Francisco Arenas
Today I was trying to add a CV file to a silverstripe form for a project and noticed that is not that easy as it sounds. Well with the help of Martijn we figured it out:
First the form