0

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:

Weilin
  • 1
  • 4
  • 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](https://getcomposer.org/doc/01-basic-usage.md#autoloading). Then find the `require '/../vendor/autoload.php` line in the `public/index.php` file ;-) gl & hf – rkeet Jul 13 '18 at 11:24
  • @rkeet, here is the composer https://github.com/nginadofficial/nginad/blob/master/upload/composer.json – Weilin Jul 26 '18 at 20:30
  • 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](https://github.com/zendframework/ZendSkeletonApplication). 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](http://php.net/manual/en/language.namespaces.php) 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 Jul 27 '18 at 08:52
  • Also, with the Zend Skeleton Application: [tutorials here](http://zendframework.github.io/). They don't have everything, but they contain a lot of info to help you get up and running quickly'ish ;-) – rkeet Jul 27 '18 at 08:54
  • 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 Jul 28 '18 at 00:16
  • Also, explained usage of Composer and usage of namespaces is general PHP knowledge, not limited to Zend Framework. So it'll help you everywhere you're doing something with PHP. – rkeet Jul 28 '18 at 00:17
  • Those images show normal Composer output. The fact that it can install means that from every requirement throughout all of the packages required, it was able to create an installable package. After installation you get recommended additional packages you can/could add. Follow links in my answer to create yourself a **local virtual host** (e.g. "http://myproject.loc" or "http://skeleton.loc"), then you get to see the image I added to my answer. If you still cannot figure it out I recommend you get other help. – rkeet Aug 02 '18 at 06:58

2 Answers2

0

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

  //...
];
  • Yes, but how to use/access Zend\Router/http/xxx from index.php in public folder? I need to set the path to zendframework3 – Weilin Jul 11 '18 at 19:52
  • Need to add newer modules, which configure and how to add it? @Joseph Stalin – Weilin Sep 26 '18 at 04:51
0

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

rkeet
  • 3,406
  • 2
  • 23
  • 49
  • Ok, seriously, what is it you're trying to do? 1 - [Download the .zip file](https://github.com/zendframework/ZendSkeletonApplication) > 2 - Extract to somewhere you host your projects > 3 - run `Composer install` in folder > 4 - Go to project URL in browser. Done. Your project is setup. – rkeet Jul 28 '18 at 10:12
  • Want to add a module? Next to folder `Application` (in `module/`), create a `NewModule` folder. Add folder `src` in there, in that create `Module.php` file. Make sure that namespace is `NewModule` in that file (`module/NewModule/src/Module.php`). Copy config function from same named class in `Application` module. Create `module/NewModule/config/module.config.php` file, have it return empty array (contents: ` – rkeet Jul 28 '18 at 10:14
  • Go to `composer.json` file in project root. Under `autoload > PSR-4` entry add `"NewModule\\" : "module/NewModule/src/"`, like in the picture in my answer. Then in terminal run `composer dump-autoload` (this re-generates the autoloading files based on updated configuration). Your new module should now be functional (doesn't do anything yet, but it's there). – rkeet Jul 28 '18 at 10:16
  • I've got an outdated tutorial on how to setup a Zend Framework **2** project on my website. The same steps still apply for Zend Framework 3. Also includes more explanations. I've been told there's still a few bugs in there somewhere, but you can figure those out along the way. [Tutorial link](https://keet.me/29/tutorials/zend-framework-2-doctrine-2-blog-tutorial). – rkeet Jul 28 '18 at 10:18
  • I just saw the edits to your question, including the screenshot. What version of Zend Framework did you start with? That looks like ZF **1** (One), correct? Are you upgrading an existing application or starting clean? If the latter, please completely remove everything and start afresh with the answer I've provided (starting with the Zend Skeleton Application, because that's a solid starting point!). Sincs ZF2 (and thus 3), there's really no need at all to change anything in the `index.php` file... ever. – rkeet Jul 29 '18 at 07:34
  • Alright, well. Sorry to say, but I've tried to help you out and I think you might have a problem understanding what I'm trying to get you to try, do and understand. So I'm halting it here. When you try out starting from scratch, following set out instructions and have read a few tutorials, please feel free to ask again. This isn't working. – rkeet Jul 30 '18 at 11:33
  • As I'm starting to fix bugs in ZF3 I can say there's some stuff not completely right :p However, no, for this situation it's what you're doing that's not right. I've asked a few times if you could start clean with the most recent Skeleton Application and just run `composer install` (nothing else). That should give you a basic project up (maybe with host configuration) with nothing else done. So far you've asked about ZF3, shown error handling of ZF2 and posted a camera image of a screen of ZF1 index.php. So, please read my answer and the comments, very literally and try again. – rkeet Jul 30 '18 at 20:30
  • Added a step by step for installing zf3 skeleton application. If you do not have any of the requirements, such as Composer or the PHP "intl" extension, google them and find out how to get them onto your system. – rkeet Jul 30 '18 at 20:41