0
I am trying to create a module "Bookstore" inside my Zend Skeleton Application, but it gives a very big error that I do not know how to deal:
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\src\ModuleManager.php(175): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent)) #1 C:\xampp\htdocs\zf2-tutorial\vendor\zendframework\zend-modulemanager\src\ModuleManager.php(97): Zend\ModuleManager\ModuleManager->loadModule('Livraria') #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
Obs: If I don’t add 'Bookstore' to the file modules.config.php the page opens normally, but gives an error ONLY on the localhost/bookstore page (localhost/application normally opens). The following error appears:
A 404 error occurred
Page not found.
The requested URL could not be Matched by routing.
No Exception available
Configuration of module.config.php:
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', ], ], ];
Configuration of Module.php:
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', ];
Configuration of 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 of 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
Thanks in advance for the help, and I really needed the solution.