« Day 4 - A habit that you wish you didn't have To my friends »

Using SilverStripe without the CMS, at all

Posted by Simon Welsh | 12 September 2010 | Comments (1)

This is a follow up post to this one. I'm assuming that you've already read it, and have a site that already doesn't use the Pages part of the CMS. This turned out to be rather easy. All I did was delete the cms folder, remove calls to methods that were on classes that no longer exist and run /dev/build. As I already had the Controllers in place, the transition was seamless.

For those that haven't read my previous post on this subject, here are the important bits form it:

I started on the frontend. This is actually rather simple to do. I made Controller subclasses (note, not ContentController nor Page_Controller, but Controller) and templates with ClassName.ss. $Layout works as expected, as do most of the normal things you can do in templates.

Finally, you just need to decide how you want your content to be accessed. You can either use class names or Director rules.

If you use class names, the URL will look like http://your-site.com/ClassName. The Link function you'll need to add to your class will be:

public function Link($action = null) {
	return __CLASS__ . ($action ? '/' . $action : '');
}

Here I'm using the magic constant __CLASS__, so you can copy and paste it straight into each class.

The second option allows you to customise your URLs. You use a similar format to our previous Director::addRules() call, except this time we don't want a redirect. I'll just use an example to explain how to do it.

Director::addRules(75, array(
	'User' => 'UserController',
	'News' => 'NewsController',
));

Here, we're adding two rules with a priority of 75. We use 75 so it has a higher than anything in sapphire. This will let our UserController be accessed by http://your-site.com/User, and likewise for the NewsController. As you can see, we can pass multiple rules in at once by adding them to the array.

The Link function in your class will be pretty much the same, but __CLASS__ will be replaced with the URL that accesses it. For example, the Link function in the NewsController class will look like:

public function Link($action = null) {
	return 'News' . ($action ? '/' . $action : '');
}

Share on FaceBook

Trackbacks

None
Trackback URL: http://simon.geek.nz/Trackbacks/add/1268

Post your comment

Sign in with Twitter

Comments

  • My back is itchy. Come scritch?

    Posted by Caitlin, 14/08/2012 12:21pm (9 months ago)

RSS feed for comments on this page | RSS feed for all comments