Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.

http://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();


13.2k

@Igor Thanks for workaround.