Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Dependency Injection in controller
  • I'm try to do Dependency Injection in controller in this way:

            public function Controller_Monkeys(Interface_Model_Monkey $model) 
    {
    $this->model = $model;
    }
          or

            public function __construct(Interface_Model_Monkey $model) 
    {
    $this->model = $model;
    }

    but I get this.

    ErrorException [ 4096 ]: Argument 1 passed to Controller_Monkeys::Controller_Monkeys() must be an instance of Interface_Model_Monkey, instance of Fuel\Core\Request given

    exist some way to do that.

    Thanks and sorry for my english.

  • You can not do that, a controller MUST have a constructor that is compatible.

    It's rather pointless to do this anyway, because controllers are called by the Request class, and MUST not be called by anything else.

    So you might have a second look at your application architecture, since it looks like you're doing something you're not meant to do.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion