0

I have started the latest tutorial for Laminas.

The routing for a new module called Provider is not working

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

  • on looking at my Module.php code I see:

getConfig() is not called but

getServiceConfig() and getControllerConfig() are.

getConfig in the Application module is not called either

<?php

namespace Provider;

use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Db\ResultSet\ResultSet;
use Laminas\Db\TableGateway\TableGateway;

use Laminas\ModuleManager\Feature\AutoloaderProviderInterface;
use Laminas\ModuleManager\Feature\ConfigProviderInterface;


class Module implements ConfigProviderInterface, AutoloaderProviderInterface
{

    public function getConfig()
    {       

        die ("getConfig");

        return include __DIR__ . '/../config/module.config.php';
    }

    public function getAutoloaderConfig()
    {   

        //die ("getAutoloaderConfig");


        //return array(
        //      'Laminas\Loader\StandardAutoloader' => array(
        //              'namespaces' => array(
        //                      __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
        //              ),
        //      ),
        //);
    }


    public function getServiceConfig()
    {   

        //die ("getServiceConfig");


        return [
                'factories' => [
                        Model\ProviderTable::class => function($container) {
                        $tableGateway = $container->get(Provider\ProviderTableGateway::class);
                        return new Model\ProviderTable($tableGateway);
                    },
                    Model\ProviderTableGateway::class => function ($container) {
                        $dbAdapter = $container->get(AdapterInterface::class);
                        $resultSetPrototype = new ResultSet();
                        $resultSetPrototype->setArrayObjectPrototype(new Model\Album());
                        return new TableGateway('provider', $dbAdapter, null, $resultSetPrototype);
                    },
                    ],
                    ];
}


    public function getControllerConfig()
    {

        //die ("getControllerConfig");


        return [
            'factories' => [
                    Controller\ProviderController::class => function($container) {
                        return new Controller\ProviderController(
                                $container->get(Model\ProviderTable::class)
                                );
                    },
                    ],
                    ];
    }





}
  • Not familiar with Laminas MVC myself. You might more likely get a response in the official Laminas forum (https://discourse.laminas.dev/). – arueckauer May 05 '20 at 10:50

4 Answers4

2

You need to enable development mode. run composer development-enable to active development mode.

sasitha999
  • 386
  • 1
  • 3
  • 12
1

Maybe the composer json is not updated (my-application/composer.json)

"autoload": {
    "psr-4": {
        "Application\\": "module/Application/src/",
        "Provider\\": "module/Provider/src/"
    }
},

Update autoload classmap:

composer dump-autoload

https://docs.laminas.dev/tutorials/getting-started/modules/#autoloading

catalinp
  • 131
  • 2
  • 5
0

Have you added router configuration?

In your attached code above you have the following function :

public function getConfig()
    {       

        //die ("getConfig");  // BE SURE YOU REMOVE THIS LINE

        return include __DIR__ . '/../config/module.config.php';
    }

it's include file for additional settings. in this file "/../config/module.config.php" you should add your router configuration. It should look like this:

return [

//... other setting

    'router' => [
        'routes' => [
            // Literal route named "home"
            'home' => [
                'type' => 'literal',
                'options' => [
                    'route' => '/',
                    'defaults' => [
                        'controller' => 'Application\Controller\IndexController',
                        'action' => 'index',
                    ],
                ],
            ],
            // Literal route named "contact"
            'contact' => [
                'type' => 'literal',
                'options' => [
                    'route' => 'contact',
                    'defaults' => [
                        'controller' => 'Application\Controller\ContactController',
                        'action' => 'form',
                    ],
                ],
            ],
        ],
    ],
];

more reading can be found https://docs.laminas.dev/laminas-router/routing/#simple-example-with-two-literal-routes

Haver
  • 443
  • 2
  • 11
  • The router configuration is in : return include __DIR__ . '/../config/module.config.php'; but this line is never called as getConfig() is not called. – user3194530 Jun 05 '20 at 10:21
0

As mentioned before any time you add a custom module you will need to add an entry for the autoloader in composer.json and run the dump-autoload. You will also need to add an entry in the root level /config/modules.config.php file. Is there currently an entry for Application? If memory serves and your working from the examples the last two should be Application, then Album. Verify those are there and that the application is in development mode. You can check the current mode with "composer development-status". Just check composer.json in the top level and look for the "scripts" entry. The key is the command to pass to composer. Also, be mindful of using the interfaces when configuring the application in the Module class. The Module feature methods are reserved for closures as they will not be cached when you disable development mode. Instead use the corresponding service manager array keys. that can be found here:

Service manager config:

https://docs.laminas.dev/laminas-servicemanager/configuring-the-service-manager/

Corresponding module manager feature config:

https://docs.laminas.dev/laminas-modulemanager/module-manager/

I suppose its worth mentioning that most if not all of the Feature interface methods map directly to a default pluginmanager implementation, ergo a specialized service manager.

Tyrsson
  • 1
  • 1
  • 3