Currently I am working on one of my projects. For this project I am using Silex micro PHP framework, because its small fast and has all tools required for my project and uses some great libraries from Symfony2 framework.
Anyway to have reusable code I wanted to create some code on my namespace. All examples on the Internet shows to use $app['autoloader']->registerNamespace...
but this functionality is deprecated and suggestion is to use Composer (composer.json). But I really didn’t wanted to use it. In fact I think micro framework should be able to setup fast without additional stuff like Composer.
Some time spent on searching found a solution. What I needed is to change first file in my controllers file to this:
//before was //require_once __DIR__.'/../vendor/autoload.php'; $loader = require_once __DIR__.'/../vendor/autoload.php';
And then add some namespaces paths to loader itself:
$loader->add('Irmantas', __DIR__ . '/../src/'); $loader->add('OtherNamespace', __DIR__ . '/../libs/other/');
Thats it and I have fully working namespace autoloader.
Iam with you in this i think micro framework must be supper fast and not complex but i think you must write your own framework it’s will be what you need anyway thank you
Nice dude, i try load with composer but, dont work.. and lost much time…
Ty for this method 😉
Pingback: Silex $app['autoloader']->registerNamespace() deprecated | Bram.us
THNX U BRO!