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

How-to: Use classes from PhalconPHP incubator in your project today!

Hello

How-to: Use classes from PhalconPHP incubator in your project today!

It's pretty simple.

Let's say you want to use: \Phalcon\Session\Adapter\Mongo

Copy the raw file that corresponds to your PhalconPHP version to the defined library directory in your application. Currently there are 1.2.x, a.2.4 and 1.3.0.

In your bootstrapper, simply use the following code:

    $di->set('session', function() use ($di, $config) {
        // When this is fully implemented by PhalconPHP, we can remove the require_once().
        require_once($config->application->libraryDir . 'Session/Mongo.php');

        $session = new \Phalcon\Session\Adapter\Mongo(array(
            'uniqueId' => $config->application->appSessionUniqueId,
            'collection' => $di->getShared('mongo')->selectCollection('sessions'),
        ));

        $session->start();

        return $session;
    });

Of course, I'm using the config.ini as seen in INVO

So, when \Phalcon\Session\Adapter\Mongo goes into the master branch, you can just delete the file and remove the require_once() call.

I hope that help you to adopt features as early as possible, testing will help to mature the framwork too.

Regards



98.9k

Thanks for contributing, however the recommended way is using composer or load classes with the autoloader:

$loader = new Phalcon\Loader();

$loader->registerNamespaces(array(
    'Phalcon' => '/path/to/incubator/Library/Phalcon/'
));

$loader->register();

https://github.com/phalcon/incubator#autoloading-from-the-incubator