From composer Install, I got newer version then the old Zend/Libeary, but got this error: atal error: Uncaught Zend\ServiceManager\Exception\ServiceNotFoundException: Unable to resolve service "Router" to a factory; are you certain you provided it during configuration? in /home/azureuser/nginad/upload/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:687 Stack trace: #0 /home/azureuser/nginad/upload/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(763): Zend\ServiceManager\ServiceManager->getFactory('Router') #1 /home/azureuser/nginad/upload/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(200): Zend\ServiceManager\ServiceManager->doCreate('Router') #2 /home/azureuser/nginad/upload/vendor/zendframework/zend-mvc/src/Application.php(158): Zend\ServiceManager\ServiceManager->get('Router') #3 /home/azureuser/nginad/upload/vendor/zendframework/zend-mvc/src/Application.php(273): Zend\Mvc\Application->bootstrap(Array) #4 /home/azureuser/nginad/upload/public/index.php(28): Zend\Mvc\Application::init(Array) #5 {main} thrown in /home/azureuser/nginad/upload/vendor/zendframework/zend-servicemanager/src/ServiceManager.php on line 687
Here is the folders where it’s installed under public
Vendor
Zendframework
Zend-Mvc
src
...
How to add Router to the configuration? Here is what I installed:
I can not understand your query clearly but if you are struggling to add routes then you can add your route in module.config.php
like below
<?php
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
return [
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
'application' => [
'type' => Segment::class,
'options' => [
'route' => '/application[/:action]',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
],
],
//...
];
Zend Skeleton Application contains this composer.json in its root project folder. You see there that it requires certain modules, including one for installation. You also see autoload
. Now, each of the to-be-loaded/required modules may do the same, creating a structure of additional composer.json files and requirements. In linked file, you see that zendframework/zend-mvc
is required ("zendframework/zend-mvc": "^3.0.1",
)
Have a look then at zendframework/zend-form's composer.json file. You'll see there additions require
keys and versions as well as an additional autoload
key. All of those (and even more) get mashed together to create a single installable package. That package is your complete installation and, after installation, everything in your vendor/
map in your project (next to the root composer.json
file of your project).
Below I've got a slightly modified (removed some stuff not relevant to question and highlighted others) screenshot of the composer.json for a current project.
On the left you see the folder structure. At the bottom you see the files composer.json
and composer.lock
.
The .json (middle screen) contains the root requirements for the project. As each package may have it's own requirements, the composer.lock
is generated during installation (file on the right). That file contains every installed version. (Created using composer install
command).
As you can see in the .lock
file, somewhere there's a requirement for the package 51systems/doctrine-encrypt
. As you can also read there, that package has it's own requirements and namespace to load.
Now, the Composer installation process also creates your autoloading.
Zend Framework kicks off autoloading in the application itself, but it uses the included files from the vendor/autoload.php
file. Below is a bit from the public/index.php
, relevant to autoload. For the full thing, install the framework or look on Github.
// Composer autoloading
include __DIR__ . '/../vendor/autoload.php';
// ... other stuff
// Run the application!
Application::init($appConfig)->run();
Ok, that shows us we're including vendor/autoload.php
. Let's see:
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit7befb6b36ba61da7e01a592b255158ab::getLoader();
Hmmm... yea, that's the entire file. Not a lot. However, we can follow this as well.
In the vendor
folder you'll find a folder named composer
. Here you'll several files starting with autoload_
, these make sure that every file registered via those composer.json
files (config PSR-0
or PSR-4
in key autoload
) get loaded.
So, including the vendor/autoload.php
really is enough. Click through them and see.
Next up you use namespaces to use other classes. You asked about that, but seeing the scope of this question, you should make that a separate question. Also, read up on namespaces with the link I send you in the comments.
Discussion is getting out of hand below, so in steps, do the following:
composer install
(from "skeleton" Terminal session) (you want to "inject into module.config.php
during installation for all options (not being picky this time), that's option 1
(every time))