Get a Service from the Container

Video loading...

Transcript language code: 

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:08
    There's a Dino Roar.RoarGenerator service in the Container.
  • 0:11
    And gosh darn it, I want to use this in my Controller.
  • 0:15
    First, notice that RoarController is not extending anything. That's cool.
  • 0:20
    Your Controller does not need to extend anything.
  • 0:23
    Drupal doesn't care.
  • 0:24
    That being said, most of the time a Controller
  • 0:27
    will extend a class called ControllerBase.
  • 0:30
    Add it and hit tab so the use statement is added above the class.
  • 0:36
    This has a lot of cool shortcut methods.
  • 0:38
    We'll look at some soon.