View more context



where the constructor looks like __construct($width) you can use

  1. YourClass:
  2. constructor:
  3. width: 40

The constructor: yaml property takes an array. But because PHP arrays and keyed arrays are the same (as opposed to JavaScript), you can key the array in a sort of self-documenting style. Be aware though, the order is important - the key means nothing.


but if you do the above, you MUST instantiate all your classes with Injector::inst()->create(YourClass::class)


otherwise you'll need to call new YourClass($widthParameter) as with normal PHP.


Arguably the docs are actually better in the class itself 😂 :P

Show 1 attachment(s)

SilverStripe Framework, the MVC framework that powers SilverStripe CMS - silverstripe/silverstripe-framework

Hide attachment content

There are other ways to do this with injector, via property setters, or public properties.

  1. public $width

You can use injector to set this property after it has created the object. OR

  1. private $width;
  2. public function setWidth($width)
  3. {
  4. $this->width = $width;
  5. }

Both of these can be set via

  1. Injector:
  2. YourClass:
  3. properties:
  4. width: 80

(be aware I've stripped the namespaces for brevity)


you may need a capital W to match the setter function if you do that way.