I've migrated my Phalcon project from 2 to 3 and get some unexpected behavior. In my loader I do this:
<?php
use Phalcon\Loader;
$loader = new Loader();
$loader->registerDirs(
array(
$config->application->libraryDir,
$config->application->controllersDir,
$config->application->modelsDir
)
);
$loader->register();
Now, when I try to instantiate one of my models in my controller-action the code halts:
$present = new \Present();
Results in a "recv() failed (104: Connection reset by peer) while reading response header from upstream" error in /var/log/nginx/error.log.
However, when I instantiate the class directly in my loader.php file the model is auto-loaded and I can instantiate it anywhere. The workaround for the controller action is:
if (class_exists('Present')) { // THIS triggers the autoloader
$present = new \Present();
$present->save();
}
So the issue is solved for now. My question is: why doesn't
new \Present()
trigger the auto-loader in the controller-action as I expected? Why did it work under Phalcon 2? Why does it work when I do it directly in the loader.php or in public/index.php?