Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

StripeCon EU 2018 - SilverStripe 4 application framework

124 views

Published on

Talk on StripeCon EU 2018: An introductory talk about using SilverStripe without pages - as an application framework in comparison to Laravel or Django

Published in: Software
  • Be the first to comment

  • Be the first to like this

StripeCon EU 2018 - SilverStripe 4 application framework

  1. 1. /me ● Web based business applications ● Technology agnostic ● PHP, Python, NodeJS, React, ● Silverstripe, Laravel, Django ● More consultant than developer
  2. 2. Criteria for frameworks ● Results fast! ● Incremental development ● Simple but extensible structure ● Stability: Static and dynamic
  3. 3. Framework Features ● ORM ● Admin Scaffolding ● Integrated security ● Form generation, scaffolding
  4. 4. Example: Everyday problems
  5. 5. Installation: Init ● Prerequisites: PHP 7.2, composer > mkdir monsters > cd monsters > composer init Minimum Stability []: dev Package Type []: project License []: BSD-3-Clause “prefer-stable”: true
  6. 6. Installation: Recipe # Important to do now! > mkdir public # Base recipe > composer require silverstripe/recipe-core # Admin > composer require silverstripe/admin # File handling > composer require silverstripe/asset-admin ...large output...
  7. 7. Installation: Confg fles # .env SS_DATABASE_CLASS="MySQLPDODatabase" SS_DATABASE_SERVER="localhost" SS_DATABASE_USERNAME="root" SS_DATABASE_PASSWORD="root" SS_DATABASE_NAME="monsters" SS_DEFAULT_ADMIN_USERNAME="admin" SS_DEFAULT_ADMIN_PASSWORD="admin" SS_ENVIRONMENT_TYPE="dev" > vendor/bin/sake dev/build # .gitignore /.env /vendor/ /silverstripe-cache/ /public/resources/ /public/assets/* /.idea
  8. 8. ModelAdmin app/src/controllers/MonsterController.php <?php namespace AppAdmin; use SilverStripeAdminModelAdmin; use AppModelsMonster; class MonsterAdmin extends ModelAdmin { private static $url_segment = "monsters"; private static $menu_title = "Monsters"; private static $menu_priority = 1; private static $managed_models = [ Monster::class ]; }
  9. 9. The Controller app/src/controllers/MonsterController.php <?php namespace AppControllers; use SilverStripeControlController; class MonsterController extends Controller { }
  10. 10. Routing app/_confg/routes.yml --- Name: approutes After: framework/_config/routes#coreroutes --- SilverStripeControlDirector: rules: 'monsters//$Action/$ID': AppControllersMonsterController '': AppControllersMonsterController
  11. 11. The View app/src/controllers/ MonsterController.php use SilverStripeControlController; use AppModelsMonster; class MonsterController extends Controller { public function index($request) { return [ 'Title' => 'Monsters', 'Objects' => Monster::get() ]; } } app/templates/App/Controllers/ MonsterController.ss <h1 class="title">$Title</h1> <% if $Monsters %> <div class="columns"> <% loop $Monsters %> <div class="column is-one-third"> <div class="box"> $Image.Fill(300, 200) <p>$Name</p> </div> </div> <% end_loop %> </div> <% end_if %>
  12. 12. Frontend editing! ● German: DAU ● Feel at home (branding) ● Everyday tasks ● Uncommon tasks As simple as possible
  13. 13. Editing app/src/controllers/MonsterController.php class MonsterController extends Controller { private static $allowed_actions = [ "edit", "EditForm" ]; public function EditForm() {…} public function edit(HTTPRequest $request) {} public function save(array $data, Form $form) {} }
  14. 14. Editing app/src/controllers/MonsterController.php:EditForm() $colors = Monster::singleton()->dbObject('Color')->enumValues(); $fields = FieldList::create( TextField::create("Name", "Name"), TextField::create("Eyes", "Number of eyes"), DropdownField::create("Color", "Main color", $colors), FileField::create("Image", "Image"), HiddenField::create("ID", "ID") ); $actions = FieldList::create( FormAction::create('save','Save')->addExtraClass('is-primary') ); $validator = RequiredFields::create('Name');
  15. 15. Editing app/src/controllers/MonsterController.php public function edit(HTTPRequest $request) { $form = $this->EditForm(); $monster = null; if($id = (int) $request->param("ID")) { $monster = Monster::get()->byID($id); $form->loadDataFrom($monster); } return [ 'Monster' => $monster, 'Form' => $form ]; }
  16. 16. Editing app/src/controllers/MonsterController.php public function save(array $data, Form $form) { if($id = $data["ID"]) { $monster = Monster::get()->byID($id); } else { $monster = Monster::create(); } $form->saveInto($monster); $monster->write(); $this->redirect($this->Link("view/$monster->ID")); }
  17. 17. SilverStripe as Framework ● Batteries included – Versioning, Translations, Extensions, REST ● Admin ● Very fast development cycle (dev/build) ● Confguration not always transparent ● SilverStripe 4 was a big step

×