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

Deploying

I just upload my app to production web server and that's what I've got:

A dependency injection object is required to access internal services
#0 /var/www/public/index.php(30): Phalcon\Mvc\Application->handle()
#1 {main}

But on localhost everything is ok. Any ideas?

And also I wanna ask, maybe somebody knows how to translate .htaccess to lighttpd config? Maybe other production-related tricks?

This error means that u didn't initialize and pass into application DI object (Application requires it, Phalcon\Mvc\Application->setDI())

I finish up with updating Phalcon from 1.0.1 to 1.1.0 on the server.



31.3k

Hi, I have the same issue here with Ubuntu server 12.04 PHP 5.4.11 and apache 2.

My application works very fine in my own environment, but when I put it online I get this error :

A dependency injection object is required to access internal services

I can't see what is wrong. I installed Phalcon and it's appear correctly in my phpinfo() loaded module.

Here's my index.php code :

<?php

error_reporting(E_ALL);

try {

/**
 * Read the configuration
 */
$config = include __DIR__ . "/../app/config/config.php";

/**
 * Read auto-loader
 */
include __DIR__ . "/../app/config/loader.php";

/**
 * Read services
 */
include __DIR__ . "/../app/config/services.php";

/**
 * Handle the request
 */
$application = new \Phalcon\Mvc\Application($di);

echo $application->handle()->getContent();

} catch (\Exception $e) { echo $e->getMessage(); }

And where is $di var initialization ?



31.3k

In the services.php file :

<?php

use Phalcon\DI\FactoryDefault, Phalcon\Mvc\View, Phalcon\Mvc\Url as UrlResolver, Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter, Phalcon\Mvc\View\Engine\Volt as VoltEngine, Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter, Phalcon\Session\Adapter\Files as SessionAdapter;

/**

  • The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault();

/**

  • The URL component is used to generate all kind of urls in the application */ $di->set('url', function() use ($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }, true);

/**

  • Setting up the view component */ $di->set('view', function() use ($config) {

    $view = new View();

    $view->setViewsDir($config->application->viewsDir);

    $view->registerEngines(array( '.volt' => function($view, $di) use ($config) {

        $volt = new VoltEngine($view, $di);
    
        $volt->setOptions(array(
            'compiledPath' => $config->application->cacheDir,
            'compiledSeparator' => '_'
        ));
    
        return $volt;
    },
    '.phtml' => 'Phalcon\Mvc\View\Engine\Php'

    ));

    return $view; }, true);

/**

  • Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function() use ($config) { return new DbAdapter(array( 'host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname )); });

/**

  • If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function() { return new MetaDataAdapter(); });

/**

  • Start the session the first time some component request the session service */ $di->set('session', function() { $session = new SessionAdapter(); $session->start(); return $session; });

Try change:

$di = new FactoryDefault();

to:

$di = \Phalcon\DI::getDefault();

But i didn't think, that this will help... Try to check full flow (with xdebug or trace output). Maybe you trying to reach DI in config.php or loader.php ?



31.3k

This the dump of my DependencyInjector. Is this normal that everything is null ?

object(Phalcon\DI\FactoryDefault)[5] protected '_services' => array (size=7) 'url' => object(Phalcon\DI\Service)[25] protected '_name' => null protected '_definition' => null protected '_shared' => null protected '_sharedInstance' => null 'config' => object(Phalcon\DI\Service)[24] protected '_name' => null protected '_definition' => null protected '_shared' => null protected '_sharedInstance' => null 'volt' => object(Phalcon\DI\Service)[23] protected '_name' => null protected '_definition' => null protected '_shared' => null protected '_sharedInstance' => null 'view' => object(Phalcon\DI\Service)[22] protected '_name' => null protected '_definition' => null protected '_shared' => null protected '_sharedInstance' => null 'db' => object(Phalcon\DI\Service)[21] protected '_name' => null protected '_definition' => null protected '_shared' => null protected '_sharedInstance' => null 'modelsMetadata' => object(Phalcon\DI\Service)[20] protected '_name' => null protected '_definition' => null protected '_shared' => null protected '_sharedInstance' => null 'session' => object(Phalcon\DI\Service)[19] protected '_name' => null protected '_definition' => null protected '_shared' => null protected '_sharedInstance' => null protected '_sharedInstances' => null protected '_freshInstance' => boolean false



31.3k

By the way the application is crashing there :

echo $application->handle()->getContent();

before this line everything is fine.



98.9k

@dlusignan what version are you using?



31.3k

PHP Version 5.4.11 Apache/2.2.22 (Ubuntu)

phalcon Phalcon Framework enabled Phalcon Version 1.2.3



98.9k

could you please compile from master again?



31.3k

The compilation I have done one the server is from 32 bits folder. The master gave me an error about lib tool.



31.3k

Yes, the server is 64 bits.



31.3k

Ha ! That was my problem, I recompiled in 64bits and "Now, I'm flying with Phalcon". Our first Phalcon tool in the company. We're migrating from Zend to Phalcon. :)



98.9k