Skip to main content

Senior Web Engineer. Open web / music. Remote DJ. Tall Dutch guy. #3million

micro.blog/sander

svandragt

mixcloud.com/cloudseer

 

Trusting the government

The UK government had setup the Independent Commision on Freedom of Information with an eye to review the Freedom Of Information Act:

Last year, the government set up a commission to review the law, composed mostly of people who had expressed scepticism or concern about the scope of the FOIA, and with a clear brief to add restrictions to its workings.

Not my definition of independent.

 

Removing index.php from SilverStripe sites

If your website has mod_rewrite enabled but the URL's generated by SilverStripe still contain 'index.php' then SilverStripe is unable to detect mod_rewrite. Adding the following line to /mysite/_config.php will address the issue (Thanks DsX):

Director::setBaseURL('/'); // fixed index.php in the URL's

 

Enum label lookup

In your datamodel you might have a Enum field such as this date-based dropdown:

public static $db = array(
    "Year"        => "Enum('2013, 2014, 2015')"
}

Internally, SilverStripe stores the index, so that when you retrieve the value in methods such as onBeforeWrite, instead of 2013 you will receive 1. Use the function below to retrieve the label of the Enum:

public function EnumLabel($field_name) {
    $enumValues = $this->dbObject($field_name)->enumValues();
    $label    = $enumValues[$this->$field_name];
    return $label;
}

// $year = $this->EnumLabel('Year');

 

LessThanOrEqual in SilverStripe 3.0

When adding a filter on a DataList sometimes you need to do a <= rather than a <. Unfortunately the LessThanOrEqual and GreatherThanOrEqual search filters do not exist in SilverStripe 3.0.x, they were added in 3.1.

Therefore we have to write our own where clause like the following example:

// Return all the sessions on or before the $date
$sessions = new DataList('AcademicSession');
$sessions = $sessions->where('"SessionStartDate" <= \'' . $date . '\'');

 

How to provide and manage your own permissions

At some point on your journey through the jungle that is SilverStripe, you will want to create permissions and assign users to them. You might have created a Page Category model admin to categorise your pages, and setup the relations between pages and their category. By default when you create a category as an admin they will not be visible to any content authors and any content authors that can access the model admin can't create any new items.

The solution to this dilemma is to create a new permission (for example PROJECT_CategoryAdmin) and then let people with that permission mange the category items. This is how to go about it:

Create the permission

You will need to tell SilverStripe you are implementing permission by changing the class declaration as follows (changes in bold):

class Category extends DataObject implements PermissionProvider

To create the new permission you will have to write a providePermissions() method for the Category class:

      public function providePermissions() {
        return array(
            "PROJECT_CategoryAdmin" => array(
                'name' => 'Administer categories',
                'category' => 'PROJECT',
                'help' => 'Manage categories.'
            )
        );
    }

Finally, implement the permission by declaring the canCreate, canDelete, canEdit and canView methods to your liking:

    public function canCreate($member = null) {
        return Permission::check('PROJECT_CategoryAdmin');
    }

    public function canDelete($member = null) {
        return Permission::check('PROJECT_CategoryAdmin');
    }

    public function canEdit($member = null) {
        return Permission::check('PROJECT_CategoryAdmin');
    }

    public function canView($member = null) {
        return Permission::check('PROJECT_CategoryAdmin') ;
    }

Don't forget to create a Role and/or assign the permission to the right Group(s), to make sure the right users can manage your categories.

 

Resolve Conflicted Files That Don't Exist

Download VisualSvn Server, open a command prompt and type svn resolved -R . to resolve all conflicts, then commit again.

 

Switched to secure connection [updated]

I've switched this site to HTTPS, a secure connection, using a ssl proxy service provided for free by Cloudflare, for reasons. Let me know if you come across any issues.

For those using WordPress, changing the settings Site Address and WordPress Address to HTTPS may make your site unavailable. FYI, the solution I settled on is to install the WordPress HTTPS plugin. Then I set the Site Address to HTTPS. Finally, I cleared the cache. All is working fine now.

Update (06/02/15):
I've moved away from Cloudflare as my DNS provider and as a side-effect this means I'm no longer HTTPS for now. Sorry.

 

Progressing your life

Lesson of life: Instead of wishing you were at a certain point with your life, think about something manageable today that you can do towards that goal.