0
votes

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

Install Screen...

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:

2
I'm thinking you're trying to make available additional classes via use statements and are using Application as an example? Have a read of autoloading classes with composer. Then find the require '/../vendor/autoload.php line in the public/index.php file ;-) gl & hfrkeet
The composer.json file you've linked is of a Zend Framework 2 project that hasn't been updated in 2 years. Are you sure it's the right project? Start with the Zend Skeleton Application. Have a look at both the public/index.php file, the composer.json file (see the PSR-4 entry in that file). Next, have a read through this of PHP Namespacing. That should get you started for "making it work". I would suggest a new question if you then still need help.rkeet
Also, with the Zend Skeleton Application: tutorials here. They don't have everything, but they contain a lot of info to help you get up and running quickly'ish ;-)rkeet
Alright, created an answer for you explaining the usage of Composer to setup a project. Really just the basics, but have a read, grab the docs and give it a go. For the usage, how and what of "namespaces" in PHP, please create another question, but do read the link I send you. Might be a lot of reading and learning, but it's worth it. It's need to know in today's PHP world.rkeet

2 Answers

0
votes

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',
                    ],
                ],
            ],
        ],
    ],

  //...
];
0
votes

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.

showing json and lock files

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:

  1. Make sure you have a host setup (On: Ubuntu (Apache), Windows 10 (Apache), Mac (Apache), Ubuntu (nginx), Windows 10 (nginx), Mac (nginx)) (have it be an empty folder for now, call it "skeleton", hostname "skeleton.loc")
  2. Download the Zend Skeleton Application (direct .zip link)
  3. Unpack in new folder from step 1 ("skeleton")
  4. Open the host folder "skeleton" in a Terminal session
  5. Run 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))
  6. Wait for installation to run
  7. Visit "skeleton.loc" (maybe canonical: http://skeleton.loc/) in your browser, you should see image below (but for ZF3 ;), ripped it from internet)

zf2 start image as demo