51
SILVERSTRIPE & SAPPHIRE From a Developer’s Perspective

SilverStripe From a Developer's Perspective

  • Upload
    ajshort

  • View
    4.803

  • Download
    4

Embed Size (px)

DESCRIPTION

The presentation I gave at the Sydney PHP Users groups on 23/11/10 about SilverStripe and Sapphire from a developer's perspective.

Citation preview

Page 1: SilverStripe From a Developer's Perspective

SILVERSTRIPE & SAPPHIREFrom a Developer’s Perspective

Page 2: SilverStripe From a Developer's Perspective

About• SilverStripe CMS is built on top of the Sapphire framework• Sapphire is a modular PHP 5, OOP, MVC framework with

lots of cool features• Supports Apache and IIS equally well• Can run on MySQL, SQLite, Postgres, MSSQL…

Page 3: SilverStripe From a Developer's Perspective

Structure• Everything is a module• Sapphire is the core module, with all (except for direct file

retrieval) requests routed through it• The CMS is an module just like any other • All code and theme assets (templates, css etc) are listed

in an automatically generated manifest - easy for the system to find

Page 4: SilverStripe From a Developer's Perspective

Modules• Module is simply a folder with a _config.php file• Installation as simple as putting a folder in the root

directory and building the DB• Defined points to hook into the base CMS functionality

using extensions• Everything is a module, including your project code

Page 5: SilverStripe From a Developer's Perspective
Page 6: SilverStripe From a Developer's Perspective

MVCLet’s look at each of those letters

Page 7: SilverStripe From a Developer's Perspective

MVC Definition• Model – contains the behaviour and data of your

application. DataObjects and ORM.• View – HTML, and other presentational elements. .ss

templates.• Controller – responds to requests and binds the model to

the view. *_Controller classes.

Page 8: SilverStripe From a Developer's Perspective

Data• You define your models as subclasses of DataObject• Define your fields, relationships, and metadata on the

class, automatically built• Uses multiple table inheritance

Page 9: SilverStripe From a Developer's Perspective

Defining Your Schema• You define your database fields in a $db array• Automatically pulls casting information from this• Define relationships in their own array• Visit or run /dev/build to rebuild the database• Done!

Page 10: SilverStripe From a Developer's Perspective
Page 11: SilverStripe From a Developer's Perspective

Easy Relationship Management• Several relationship types – has_one, belongs_to,

has_many, many_many, belongs_many_many• Easy accessing:

• $this->Relationship($filter);• $this->Relationship()->addMany($items)• $this->Relationship()->map()

Page 12: SilverStripe From a Developer's Perspective

Page Types• Complex DataObject, forms the core of most websites• Managed via the main admin panel in the CMS• Easy to customise, can contain any type of data• Make SilverStripe ideal for your data, not the other way

around• Each page type is coupled to its own controller

Page 13: SilverStripe From a Developer's Perspective
Page 14: SilverStripe From a Developer's Perspective
Page 15: SilverStripe From a Developer's Perspective

Retrieving Data• Simple accessors – DataObject::get() and DataObject::get_one()

• Can use SQLQuery and DB::query() to peek behind the ORM

• Automatically caches certain things, performs default sorts and allows hooking into the process

Page 16: SilverStripe From a Developer's Perspective

Changing Data• $object->Field = $value• $object->write()• $object->publish(‘Stage’, ‘Live’)• $object->delete()

Page 17: SilverStripe From a Developer's Perspective

Extensions (AKA Decorators)• Add functionality to classes at runtime, without

subclassing• Can add new methods, database fields, change and

enhance behaviour• Many core processes have hooks that extensions can

hook in to• Object::add_extension($subject, $extension)

Page 18: SilverStripe From a Developer's Perspective

Extensions Continued• Add new database fields and form fields in the CMS• Lock a user out if a third-party criteria is not met• Change the permissions model to either force permissions

allowed or denied• Add image editor support to the CMS image insertion form• Restrict content to a specific subsite• Add extra fields to the member profile• Add static caching to the publishing process

Page 19: SilverStripe From a Developer's Perspective

Core Extensions• Versioned – adds support for staging/publishing, as well

as rolling back to specific versions• Hierarchy – Allows for a tree of objects to be stored in the

DB, with related utiltity methods• Translatable – Adds support for saving multiple languages

in one table, switch between languages, edit in CMS

Page 20: SilverStripe From a Developer's Perspective

Much more than just data• Extensions can hook into all parts of SilverStripe• Basically anywhere a developer calls • $this->extend(‘methodName’) you can hook extra

behaviour in

Page 21: SilverStripe From a Developer's Perspective

Easy Forms• Out of the box scaffolding• Rich form library, with both simple and complex widgets• Form fields easily integrate with your models, save

relationships• $form->saveInto($record);$record->write();

Page 22: SilverStripe From a Developer's Perspective

Form Library• Simple Fields – TextField, DropdownField, DateField• Structure Fields – HeaderField, LiteralField• Relationship Fields – ComplexTableField,

CheckboxSetField• Much much much more!• Many fields in modules, and its easy to create your own!

Page 23: SilverStripe From a Developer's Perspective

Forms in the CMS• Simple to add fields in the CMS• Just overload getCMSFields on your DataObject, and call:$fields->addFieldToTab(‘Root.Tab’, $field)

• Can also hook in using extensions to modify the fields on existing objects without subclassing

Page 24: SilverStripe From a Developer's Perspective

ModelAdmin• Fully scaffolded CRUD interface, with easy searching.• Easily customisable, anything can be changed.• Can be extended to very complex use cases.

Page 25: SilverStripe From a Developer's Perspective
Page 26: SilverStripe From a Developer's Perspective
Page 27: SilverStripe From a Developer's Perspective

Templating• Simple templating language, cached as raw PHP• Not XML based, used for emails, HTML, all kinds of things• Doesn’t limit the markup you can create• Theming system for bundling templates• Layout and include support across modules

Page 28: SilverStripe From a Developer's Perspective
Page 29: SilverStripe From a Developer's Perspective

Requirements• System to include, and block CSS and JS assets from

templates and PHP code• Supports minifying and combining• Requirements::css(‘mysite/css/my.css’)Requirements::themedCSS(‘mycss’)<% require javascript (mysite/css/my.css) %>

Page 30: SilverStripe From a Developer's Perspective

Controllers• Simple URL routing:Director::addRules($priority, $rules)

• RequestHandler is a simple barebones controller, just takes a response and returns a response

• Controller has more utility methods, support for actions etc.

Page 31: SilverStripe From a Developer's Perspective

Controllers Continued• Once the initial URL routing is done, the request is still not

always done.• A controller can return a controller as its result, which then

moves down the URL and uses that controller to parse the request

• This means you can easily create complex controllers from several controllers

• For example, the CMS controller returns a Form object, which then leads to a form field, which then renders a pop up

• Cascading permissions!

Page 32: SilverStripe From a Developer's Perspective

Page Controllers• Each page type also has a corresponding controller,

which handles the actual request• Can easily define custom actions, methods as you would

expect• Can also define controllers without a matching page to

simulate a page without actually having one

Page 33: SilverStripe From a Developer's Perspective
Page 34: SilverStripe From a Developer's Perspective

THAT’S A QUICK OVERVIEW OF SOME OF THE CORENow for some cool random features!

Page 35: SilverStripe From a Developer's Perspective

Caching Support• Supports full page caching, with optional header

management• Can rsync to remote hosts• Automatically updates cache on publish• Partial caching, with automatic invalidation• Integration with Zend_Cache

Page 36: SilverStripe From a Developer's Perspective

2008 DNC

Page 37: SilverStripe From a Developer's Perspective

2008 DNC• One private CMS server, rsynced static content out to

several other servers• 100M+ page view• 350 000 hours of HD video, some live• Bi-lingual• Could still make changes to site during heavy load times

Page 38: SilverStripe From a Developer's Perspective

Easy API’s• Simple SOAP and RESTful API’s out of the box• Easily convert data to and from XML, JSON, form

encoding• Utility classes for consuming APIs• Easily expose updates via RSS

Page 39: SilverStripe From a Developer's Perspective

Translation and Internationalisation

• Support for simple string translation with PHP language files (in templates as well)

• Javascript translation support• DataObjects can have an extension applied to add

translatable support• Full translation support in the CMS

Page 40: SilverStripe From a Developer's Perspective

Reports• Two types of reports – simple lists of pages in the CMS

and more complex reports in their own tab• You can easily define your own reports by extending

SS_Report• Just implement a few methods and you’re done!

Page 41: SilverStripe From a Developer's Perspective
Page 42: SilverStripe From a Developer's Perspective

SearchContext• Allows you to define an “advanced search” interface for

your DataObjects• Scaffolded by default, and used in ModelAdmin• Works in both ModelAdmin and the frontend easily• Define advanced search forms with simple code by using

“search filters”

Page 43: SilverStripe From a Developer's Perspective
Page 44: SilverStripe From a Developer's Perspective
Page 45: SilverStripe From a Developer's Perspective

And much more• Configurable error handling, emailing and logging.• Easily create scheduled and build tasks• Insert dynamic content into html text fields using

shortcodes• Define widgets with a simple drag and drop interface• Sake for running silverstripe commands from the CLI• Easy environment-specific configuration• Page comments

Page 46: SilverStripe From a Developer's Perspective

Cool Modules!• User Forms• Queued Jobs• Forum• Blog• Workflow• Sphinx, Solr, Zend_Lucene• Spam protection – recaptcha, mollom..• And many more!

Page 47: SilverStripe From a Developer's Perspective

User Forms Module

Page 48: SilverStripe From a Developer's Perspective

DB Plumber

Page 49: SilverStripe From a Developer's Perspective

Pixlr Image Editor

Page 50: SilverStripe From a Developer's Perspective

What’s Next?• SilverStripe 3 is currently being talked about• New ORM?• New template parser?• Revamped media and download handling?• Better module and configuration management?• More cowbell?

Page 51: SilverStripe From a Developer's Perspective

Any Questions?