We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Does DI setter injection work with a \Phalcon\Mvc\Collection

Using Phalcon 1.1.0 and trying to get the DI to work on a \Phalcon\Mvc\Collection

$di->set('myservice', function() {
    return $myservice = new myService();
});
$di->set('Data', array(
    'className' => 'Namespace\Model\Data',
    'calls' => array(
        array(
            'method' => 'setMyservice',
            'value' => array('type' => 'service', 'name' => 'myservice')
        ),
    )
));

But the corresponding method in the collection class never gets called. What am I doing wrong?



98.9k

Check this gist out, you have an error on how you're passing the parameters for setMyservice: https://gist.github.com/phalcon/5695689

https://docs.phalcon.io/en/latest/reference/di.html#setter-injection