Fatal error when creating a new Zend Skeleton Application module

0

I'm trying to create a "Bookstore" module inside my Zend Skeleton Application, however it gives a very big error that I do not know how to handle:

  

Fatal error: Uncaught exception 'Zend \ ModuleManager \ Exception \ RuntimeException' with message 'Module (Bookstore) could not be initialized.' in C: \ xampp \ htdocs \ zf2-tutorial \ vendor \ zendframework \ zend-modulemanager \ src \ ModuleManager.php: 203 Stack trace: # 0 C: \ xampp \ htdocs \ zf2-tutorial \ vendor \ zendframework \ zend-modulemanager \ zend-modulemanager \ Zend \ ModuleManager \ moduleManager-> (Object (Zend \ ModuleManager \ ModuleEvent)) # 1 C: \ xampp \ htdocs \ zf2-tutorial \ vendor \ zendframework \ src \ ModuleManager.php (97): Zend \ ModuleManager \ ModuleManager-> loadModule ('Library') # 2 C: \ xampp \ htdocs \ zf2-tutorial \ vendor \ zendframework \ zend-eventmanager \ src \ EventManager.php 271): Zend \ ModuleManager \ ModuleManager-> onLoadModules (Object (Zend \ ModuleManager \ ModuleEvent)) # 3 C: \ xampp \ htdocs \ zf2-tutorial \ vendor \ zendframework \ zend-eventmanager \ src \ EventManager.php (143 ): Zend \ EventManager \ EventManager-> triggerListeners (Object (Zend \ ModuleManager \ ModuleEvent)) # 4 C: \ xampp \ htdocs \ zf2-tutorial \ vendor \ zendframework \ zend-moduleman in C: \ xampp \ htdocs \ zf2 -tutorial \ vendor \ zendframework \ zend-modulemanager \ src \ ModuleManager .php on line 203

Note: If I do not add 'Livraria' in the modules.config.php file the page opens normally but gives a JUST on the localhost / bookstore page (the localhost / application page opens normally). The following error appears:

  

A 404 error occurred
  Page not found.   The requested URL could not be matched by routing.
  No Exception available


module.config.php configuration:

namespace Livraria;

use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;

return [
    'router' => [
        'routes' => [
            'livrariahome' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/livraria',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/livraria[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],
    'controllers' => [
        'factories' => [
            Controller\IndexController::class => InvokableFactory::class,
        ],
    ],
    'view_manager' => [
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => [
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'livraria/index/index' => __DIR__ . '/../view/livraria/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ],
        'template_path_stack' => [
            __DIR__ . '/../view',
        ],
    ],
];

Module.php configuration:

namespace Livraria;

class Module
{
    const VERSION = '3.0.2dev';

    public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }
}

Configuration of modules.config.php :

return [
    'Zend\Router',
    'Zend\Validator',
    'Application',
    'Livraria',
];

Setting the IndexController.php :

namespace Livraria\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        $nome = 'Olá Livraria';
        return new ViewModel(array('nome' => $nome));
    }
}

Paths to folders :

module/
  Livraria/
     config/
        module.config.php
     src/
        Controller/
            IndexController.php
        Module.php
     view/
        error/
            404.php
            index.phtml
        layout/
            layout.phtml
        livraria/
            index/
               index.phtml

Thank you in advance for the help, and I needed the solution very much.

    
asked by anonymous 16.01.2017 / 05:12

2 answers

0

I think the problem is in your "src" folder. The correct would be to have a folder with the name of the module and, yes, to have the folder controller and the file Module.php, exemplified below.

module/
      Livraria/
         config/
            module.config.php
         src/
            Livraria/
                Controller/
                     IndexController.php
                Module.php
         view/
            error/
                404.php
                index.phtml
            layout/
                layout.phtml
            livraria/
                index/
                   index.phtml
    
16.01.2017 / 16:41
0

Your Module.php file is in the wrong place, it needs to be in the root folder of your module:

module/
    Livraria/
        config/
            module.config.php
        src/
            Livraria/
                Controller/
                    IndexController.php        
        view/
            error/
                404.php
                index.phtml
            layout/
                layout.phtml
            livraria/
                index/
                    index.phtml
        Module.php
    
20.01.2017 / 18:17