asgrim / book-library

Demo application using Expressive that I use in talks
MIT License
25 stars 9 forks source link

ServiceNotFoundException #4

Open persianphilosopher opened 6 years ago

persianphilosopher commented 6 years ago

Hi there,

Listened to your talk on YouTube which convinced me to give Zend another shot.

It's likely my lack of familiarity with Zend but I can't get this going at all. Did a clean clone, composer install etc. At first, I get the following errors.

First, in the server log: file_put_contents(data/cache/config-cache.php): failed to open stream: No such file or directory in /var/www/book/vendor/zendframework/zend-config-aggregator/src/ConfigAggregator.php on line 256

I created the data/cache folder and it did cache everything in config-cache.php

Then, this error persists in the browser: {"message":"Service with name \u0022Doctrine\\ORM\\EntityManagerInterface\u0022 could not be created. Reason: An exception occurred in driver: SQLSTATE[08006] [7] missing \u0022=\u0022 after \u0022this\u0022 in connection info string","line":771,"file":"/var/www/book/vendor/zendframework/zend-servicemanager/src/ServiceManager.php"}

The above two errors were thrown on three different installs. There is one error that I caught only once in the server logs but I did not find it again upon reinstalls:

PHP message: PHP Fatal error: Uncaught Zend\ServiceManager\Exception\ServiceNotFoundException: Unable to resolve service "Zend\Expressive\Application"to a factory; are you certain you provided it during configuration? in /var/www/book/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:687

As I said above, I am not very familiar with Zend and it's likely that there is a step that I should follow but don't know it. Before I go back playing with Slim/Laravel, I thought to at least mention it in case it's not just my ignorance causing these errors.

asgrim commented 6 years ago

Hey there - glad the first issue got resolved.

Looking at the README.md it looks like the configuration step is missing really. To fix this (and disable config caching - that's only needed in production):

<?php
declare(strict_types=1);

use Zend\ConfigAggregator\ConfigAggregator;

return [
    'debug' => true, // ensure this is true in development!
    ConfigAggregator::ENABLE_CACHE => false, // ensure this is false in development!
    'doctrine' => [
        'connection' => [
            'orm_default' => [
                'params' => [
                    'url' => 'postgres://user:pass@host/dbname', // This depends on your DB used... (MySQL, PostgreSQL, etc. - basically anything Doctrine DBAL supports)
                ],
            ],
        ],
    ],
];

Hope this helps, and indeed was a failing of the setup instructions, not you! :+1: