silverstripe

#silverstripe 1

1: 2

2

2

Examples 2

2

CMS / 2

2: DataExtensions 4

Examples 4

DataObject 4

DataObject 4

DataExtension 4

3: LeftAndMain 6

6

Examples 6

1. 6

6

6

6

2. HelloWorldLeftAndMain. 6

7

7

7

3. (HelloWorldLeftAndMain_Content.ss) 8

. 8

8

4: ModelAdmin 9

Examples 9

9

UI DataObject 9

DataObject . 9 DataObject 9

searchable_fields ModelAdmin . 10

GridField 10

ModelAdmin 11

5: ORM 12

Examples 12

DataObject 12

6: 13

13

? 13

13

Examples 13

13

13

YAML 13

13

7: 15

15

Examples 15

SilverStripe Grid 15

GridField 15

15

15

CMS 16

16

8: 17

17

Examples 17

17

AJAX 17

17 19

20

: 20

9: 22

22

Examples 22

MyClass.php 22

23 You can share this PDF with anyone you feel could benefit from it, downloaded the latest version from: silverstripe

It is an unofficial and free silverstripe ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow. It is neither affiliated with Stack Overflow nor official silverstripe.

The content is released under Creative Commons BY-SA, and the list of contributors to each chapter are provided in the credits section at the end of this book. Images may be copyright of their respective owners unless otherwise specified. All trademarks and registered trademarks are the property of their respective company owners.

Use the content presented in this book at your own risk; it is not guaranteed to be correct nor accurate, please send your feedback and corrections to [email protected]

https://riptutorial.com/ko/home 1 1:

Silverstripe PHP . .

• BSD - . • . • .

, MySQL .

3.4.0 2016-06-03

Examples

SilverStripe zip .

.

create-project silverstripe/installer /path/to/project 3.4.0 zip SilverStripe . .

SilverStripe .

CMS /

SilverStripe CMS CMS , . config.yml .

LeftAndMain: application_name: 'My Application' application_link: 'http://www.example.com/' extra_requirements_css: - mysite/css/cms.css mysite / css / cms.css

.ss-loading-screen { background: #fff; } .ss-loading-screen .loading-logo { background: transparent url('../images/my-logo-loading.png') no-repeat 50% 50%; } .cms-logo a { background: transparent url('../images/my-logo-small.png') no-repeat left center; }

https://riptutorial.com/ko/home 2 : https://riptutorial.com/ko/silverstripe/topic/1771/--

https://riptutorial.com/ko/home 3 2: DataExtensions

Examples

DataObject

DataExtension DataObject .

class MyMemberExtension extends DataExtension { private static $db = [ 'HairColour' => 'Varchar' ]; }

.

# File: mysite/_config/app.yml Member: extensions: - MyMemberExtension

HairColour Member .

DataObject

DataObject public . .

class MyMemberExtension extends DataExtension { public function getHashId() { return sha1($this->owner->ID); } }

Member sha1 Member ID Member $this->owner . :

$member = Member::get()->byId(123); var_dump($member->getHashId()); // string(40) "40bd001563085fc35165329ea1ff5c5ecbdbbeef"

DataExtension

Config . :

# File: mysite/_config/config.yml Member: extensions: - MyMemberExtension https://riptutorial.com/ko/home 4 extensions "array" .

# File: mysite/_config/config.yml Member: extensions: - MyMemberExtension - MyOtherMemberExtension

.

DataExtensions : https://riptutorial.com/ko/silverstripe/topic/3519/dataextensions

https://riptutorial.com/ko/home 5 3: LeftAndMain

LeftAndMain API ModelAdmin . ModelAdmin LeftAndMain .

Examples

1.

LeftAndMain .

Hello World .

CMS 3.* 3.* 4.* .

SS4 FQCN (Full Quality Class Name) .

tl; dr .

1. /helloworld/ _config.php . SilverStripe . SilverStripe _config.php .

2. /code/ . /admin/ .

3. /helloworld/code/admin/HelloWorldLeftAndMain.php .

class HelloWorldLeftAndMain extends LeftAndMain {

}

4. /helloworld/templates/Includes/HelloWorldLeftAndMain.ss .

/framework/ /cms/ /helloworld/ + _config.php + /code/ + /admin/ + /HelloWorldLeftAndMain.php + /templates/ + /Includes/ + /HelloWorldLeftAndMain_Content.ss

2. HelloWorldLeftAndMain.php

.

https://riptutorial.com/ko/home 6 class HelloWorldLeftAndMain extends LeftAndMain {

}

$url_segment , ( $menu_title )

private static $url_segment = 'helloworld'; private static $menu_title = 'Hello World';

.

private static $menu_icon = 'helloworld/path/to/my/icon.png'; private static $url_rule = '/$Action/$ID/$OtherID';

LeftAndMain LeftAndMain init . . CSS .

, CMS ( : 3.* ~ 4.* . 3.* CSS 4.* 4.* ) helloworld/css/styles.css .

public function init() { parent::init();

Requirements::css('helloworld/css/styles.css'); //Requirements::('helloworld/javascript/script.min.js'); }

Javascript Javascript .

$allowed_actions Page_Controller Page_Controller .

index() index() override index() . index() HelloWorldLeftAndMain_Content.ss ( ).

class HelloWorldLeftAndMain extends LeftAndMain { private static $url_segment = 'helloworld'; private static $menu_title = 'Hello World'; private static $allowed_actions = array( 'some_action' );

public function init() { parent::init();

Requirements::css('helloworld/css/styles.css'); //Requirements::javascript('helloworld/javascript/script.min.js'); }

https://riptutorial.com/ko/home 7 public function Hello($who=null) { if (!$who) { $who = 'World'; }

return "Hello " . htmlentities($who); } }

3. (HelloWorldLeftAndMain_Content.ss)

.

1. .

• .north • .center • .south

2. data-pjax-fragment="Content" . AJAX "Content" .

SilverStripe .

; <% include CMSBreadcrumbs %> <% include CMSBreadcrumbs %> . CSS

<%-- This will add the breadcrumb that you see on every other menu item --%>
<% include CMSBreadcrumbs %>

<%-- Our function in HelloWorldLeftAndMain.php --%> $Hello('USER'); <%-- ^ outputs "Hello USER" --%>

Some footer-worthy content

/dev/build ?flush=1 !

LeftAndMain : https://riptutorial.com/ko/silverstripe/topic/8300/leftandmain https://riptutorial.com/ko/home 8 4: ModelAdmin

Examples

DataObject :

class MyDataObject extends DataObject { private static $db = array( 'Name' => 'Varchar(255)' ); }

Create-Read-Update-Delete ModelAdmin .

class MyModelAdmin extends ModelAdmin { private static $mangaged_models = array( 'MyDataObject' ); private static $url_segment = 'my-model-admin'; private static $menu_title = 'My Model Admin'; private static $menu_icon = 'mysite/images/treeicons/my-model-admin.png'; private static $menu_priority = 9; }

UI DataObject

class MyDataObject extends DataObject {

private static $singular_name = 'My Object'; private static $plural_name = 'My Objects';

... }

DataObject .

class SortDataObject extends DataObject {

private static $db = array( 'Name' => 'Varchar', 'SortOrder' => 'Int' );

private static $default_sort = 'SortOrder DESC'; }

DataObject

class MyDataObject extends DataObject {

https://riptutorial.com/ko/home 9 private static $db = array( 'Name' => 'Varchar' );

private static $has_one = array( 'OtherDataObject' => 'OtherDataObject' );

private static $summary_fields = array( 'Name', 'OtherDataObject.Name' );

private static $field_labels = array( 'OtherDataObject.Name' => 'Other Data Object' ); }

ModelAdmin summary_fields . field_labels field_labels field_labels . searchable_fields ModelAdmin .

class MyDataObject extends DataObject {

private static $db = array( 'Name' => 'Varchar' );

private static $has_one = array( 'OtherDataObject' => 'OtherDataObject' );

private static $summary_fields = array( 'Name', 'OtherDataObject.Name' );

private static $searchable_fields = array( 'Name', 'OtherDataObjectID' => array( 'title' => 'Other Data Object' ) );

}

OtherDataObjectID .

GridField

class MyDataObject extends DataObject {

...

private static $has_many = array( 'OtherDataObjects' => 'OtherDataObject' ); https://riptutorial.com/ko/home 10

function getCMSFields() { $fields = parent::getCMSFields();

if ($gridField = $fields->dataFieldByName('OtherDataObjects')) { $gridField->getConfig() ->removeComponentsByType('GridFieldExportButton'); }

return $fields; } }

ModelAdmin

class MyAdmin extends ModelAdmin {

...

function getEditForm($id = null, $fields = null) { $form = parent::getEditForm($id, $fields);

if ($this->modelClass == 'MyDataObjectName') { $form->Fields() ->fieldByName($this->sanitiseClassName($this->modelClass)) ->getConfig() ->removeComponentsByType('GridFieldExportButton'); } return $form; } }

ModelAdmin : https://riptutorial.com/ko/silverstripe/topic/3836/modeladmin

https://riptutorial.com/ko/home 11 5: ORM

Examples

DataObject

SilverStripe DataObject . .

DataObject .

class Fruit extends DataObject { private static $db = ['Name' => 'Varchar']; }

Fruit .

$apple = Fruit::create(); $apple->Name = 'Apple'; $apple->write();

Fruit .

$apple = Fruit::get()->filter('Name', 'Apple')->first(); var_dump($apple->Name); // string(5) "Apple"

ORM : https://riptutorial.com/ko/silverstripe/topic/3463/orm-

https://riptutorial.com/ko/home 12 6:

?

SilverStripe . , API .

Config dev/build cache flush ( URL ?flush ) SS_ConfigStaticManifest .

SS_ConfigStaticManifest PHP YAML SS_ConfigStaticManifest .

YAML private static Config .

Examples

Config .

1. SilverStripe private static 2. (module-folder / _config / [file] .yml ) 3. PHP ( Config::inst()->update('Director', 'environment_type', 'dev')

2 .

class MyDataObject extends DataObject {

private static $db = array( 'Title' => 'Varchar', );

}

SilverStripe ( vendor/ ) private static Config . YAML mysite/_config/config.yml ( YAML ) .

Director: environment_type: dev

YAML Config .

mysite/_config.php . https://riptutorial.com/ko/home 13 Config::inst()->update('Director', 'environment_type', 'dev');

PHP Config .

: https://riptutorial.com/ko/silverstripe/topic/4699/-

https://riptutorial.com/ko/home 14 7:

Addons Packagist SilverStripe .

Composer .

Examples

SilverStripe Grid

SilverStripe Grid Field Extensions Module GridField ...

• GridFieldAddExistingSearchButton - • GridFieldAddNewInlineButton - GridFieldEditableColumns . • GridFieldAddNewMultiClass - . • GridFieldEditableColumns - . • GridFieldOrderableRows - • GridFieldRequestHandler - , CMS • GridFieldTitleHeader -

.

GridField

GridField Better Buttons GridField .

• : . • : . • : . . • : . • / : . • ...

( )

UserForms CMS PHP .

• (, , , , ...) • . • • CSV • • . • . github .

https://riptutorial.com/ko/home 15 . JavaScript .

...

$products->displayIf("HasProducts")->isChecked();

$sizes->hideUnless("ProductType")->isEqualTo("t-shirt") ->andIf("Price")->isGreaterThan(10);

$payment->hideIf("Price")->isEqualTo(0);

$shipping->displayIf("ProductType")->isEqualTo("furniture") ->andIf() ->group() ->orIf("RushShipping")->isChecked() ->orIf("ShippingAddress")->isNotEmpty() ->end(); readme.md .

CMS

CMS CMS . CMS .

SilverStripe 3 CMS . . CMS .

.

...

• • • RSS • • • Google •

. ...

Member::create(array( 'HasConfiguredDashboard' => 1 )); readme.md .

: https://riptutorial.com/ko/silverstripe/topic/4339/---

https://riptutorial.com/ko/home 16 8:

• Form :: create ($ this, __FUNCTION__, $ fields, $ actions, $ validator) // • Form :: create (...) -> addExtraClass ( 'my-css-class another-class') // CSS • Form :: create (...) -> loadDataFrom (Member :: get () -> byID (1)); // .

Examples

, .

class Page_Controller extends ContentController {

private static $allowed_actions = array( 'ExampleForm' );

public function ExampleForm() { $fields = FieldList::create( TextField::create('Name', 'Your Name') );

$actions = FieldList::create( FormAction::create('doExampleFormAction', 'Go') );

$requiredFields = RequiredFields::create('Name');

$form = Form::create( $this, 'ExampleForm', $fields, $actions, $requiredFields );

return $form; }

public function doExampleFormAction($data, Form $form) { $form->sessionMessage('Hello '. $data['Name'], 'success');

return $this->redirectBack(); } }

$ExampleForm .

$ExampleForm

AJAX

SilverStripe AJAX . AJAX ( ) Form .

https://riptutorial.com/ko/home 17 . Page_Controller Page_Controller .

class Page_Controller extends ContentController {

/** * A list of "actions" (functions) that are allowed to be called from a URL * * @var array * @config */ private static $allowed_actions = array( 'Form', 'complete', );

/** * A method to return a Form object to display in a template and to accept form submissions * * @param $request SS_HTTPRequest * @return Form */ public function Form($request) { // include our javascript in the page to enable our AJAX behaviour Requirements::javascript('framework/thirdparty//jquery.js'); Requirements::javascript('mysite/javascript/ajaxforms.js'); //create the fields we want $fields = FieldList::create( TextField::create('Name'), EmailField::create('Email'), TextareaField::create('Message') ); //create the button(s) we want $buttons = FieldList::create( FormAction::create('doForm', 'Send') ); //add a validator to make sure the fields are submitted with values $validator = RequiredFields::create(array( 'Name', 'Email', 'Message', )); //construct the Form $form = Form::create( $this, __FUNCTION__, $fields, $buttons, $validator );

return $form; }

/** * The form handler, this runs after a form submission has been successfully validated * * @param $data array RAW form submission data - don't use * @param $form Form The form object, populated with data * @param $request SS_HTTPRequest The current request object */ https://riptutorial.com/ko/home 18 public function doForm($data, $form, $request) { // discard the default $data because it is raw submitted data $data = $form->getData();

// Do something with the data (eg: email it, save it to the DB, etc

// send the user back to the "complete" action return $this->redirect($this->Link('complete')); }

/** * The "complete" action to send users to upon successful submission of the Form. * * @param $request SS_HTTPRequest The current request object * @return string The rendered response */ public function complete($request) { //if the request is an ajax request, then only render the include if ($request->isAjax()) { return $this->renderWith('Form_complete'); } //otherwise, render the full HTML response return $this->renderWith(array( 'Page_complete', 'Page', )); }

}

Page_Controller . Page_Controller Page_Controller ContactPage .

.

• Form • ( Form ) • complete .

. Layout / Page.ss .

<% include SideBar %>

$Title

$Content
$Form
$CommentsForm

.

Layout/Page_complete.ss - form-holder div .

https://riptutorial.com/ko/home 19

<% include Form_complete %>

Includes/Form_complete - AJAX .

Thanks, we've received your form submission!

We'll be in touch as soon as we can.

, AJAX (mysite / javascript / ajaxform.js ).

(function($) { $(window).on('submit', '.js-ajax-form', function(e) { var $form = $(this); var formData = $form.serialize(); var formAction = $form.prop('action'); var formMethod = $form.prop('method'); var encType = $form.prop('enctype');

$.ajax({ beforeSend: function(jqXHR,settings) { if ($form.prop('isSending')) { return false; } $form.prop('isSending',true); }, complete: function(jqXHR,textStatus) { $form.prop('isSending',false); }, contentType: encType, data: formData, error: function(jqXHR, textStatus, errorThrown) { window.location = window.location; }, success: function(data, textStatus, jqXHR) { var $holder = $form.parent(); $holder.fadeOut('normal',function() { $holder.html(data).fadeIn(); }); }, type: formMethod, url: formAction }); e.preventDefault(); }); })(jQuery);

AJAX . :

"ajaxified"() ( : ). .

Page_Controller https://riptutorial.com/ko/home 20 Form Page_Controller .

public function Form() { ... $form->addExtraClass('js-ajax-form'); return $form; } javascript .

$(window).on('submit', '.js-ajax-form', function(e) { ... })(jQuery); js-ajax-form .

: https://riptutorial.com/ko/silverstripe/topic/4126/

https://riptutorial.com/ko/home 21 9: dev / build? flush = 1 .

Examples

MyClass.php

class MyClass { ... }

class OtherClass { ... }

?>

Silverstripe .

OtherClass .

MyPage.php

class MyPage_Controller extends BookingPage_Controller { ... }

?>

"_Controller" .

"_manifest_exclude" .

: https://riptutorial.com/ko/silverstripe/topic/3817/

https://riptutorial.com/ko/home 22 S. Contributors No

1 3dgoo, Barry, Community, zanderwar

2 DataExtensions bummzack, Dan Hensby, Robbie Averill

3 LeftAndMain zanderwar

4 ModelAdmin 3dgoo, Barry, Turnerj

5 ORM 3dgoo, bummzack, Robbie Averill

6 Dan Hensby

7 Barry

8 3dgoo, Dan Hensby

9 Barry

https://riptutorial.com/ko/home 23