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

Class Phalcon\Mvc\Collection without DI

How can I use Class Phalcon\Mvc\Collection in a stand-alone manner without DI? In other word how can I specify mongo connection manually?

How can I access native MongoCollecton class that is use by Phalcon\Mvc\Collection? Currently I use $this->getConnection()->{$this->getSource()}->findOne();. The problem is that getConnection is not static and I can not write static method in Model using that.

https://stackoverflow.com/q/15722109/752603



368
Accepted
answer
edited Mar '14

Try:

class MymodelName {

    static function model(){
       return new MymodelName()->getConnection()->getSource();
    }
}

MymodelName::model()->findOne();


22.1k

@Igor Thanks for workaround.