nightjarnz

I hope this has been informative, I must do work now :P

nightjarnz

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

nightjarnz

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)

nightjarnz

Arguably the docs are actually better in the class itself 😂 :P https://github.com/silverstripe/silverstripe-framework/blob/4.4.4/src/Core/Injector/Injector.php#L18-L131

Show 1 attachment(s)
GitHub  
silverstripe/silverstripe-framework

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

Hide attachment content
nightjarnz

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