ZF3 error 404 for a specific module name

Asked

Viewed 73 times

0

I have a route on my website which is linked to a module called Cart, but although everything seems to be according to the tutorial and documentation of zend, this route is not found and always from erro 404.

After several attempts of different modifications to see if the code worked, I then modified the name of the module for Cart2, and also the namespaces of their respective files (Controllers, Entities, Models...). Oddly enough, the route is now found, only changing the name of the module. But it is really necessary that the module name is Cart.

I gave one Find on the project to see if that word Cart was in some configuration file that could compromise the module with that name and found nothing.

Has anyone there been through it and/or has an idea of what it might be?

modules/Cart/config/module.config.php:

<?php

namespace Carrinho;

use Zend\Router\Http\Segment;

return array(
    'router' => array(
        'routes' => array(
            'carrinho' => array(
                'type'    => Segment::class,
                'options' => array(
                    'route' => '/carrinho[/:action][/:produto][/:dados]',
                    'constraints' => array(
                        'action'   => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'produto'   => '[a-zA-Z0-9_,]*',
                        'dados' => '[a-zA-Z0-9_=]*',
                    ),
                    'defaults' => array(
                        'controller' => Controller\CarrinhoController::class,
                        'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),

    'view_manager' => array(
        'template_path_stack' => array(
            'carrinho' => __DIR__ . '/../view',
        ),
    ),

    'asset_manager' => array( 
        'resolver_configs' => array( 
            'paths' => array( 
                __DIR__ . '/../asset', 
            ), 
        ),
     ),
);

module/Cart/src/Module.php:

<?php

namespace Carrinho;

use Zend\ModuleManager\Feature\ConfigProviderInterface;

class Module implements ConfigProviderInterface
{
    const VERSION = '3.0.3-dev';

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

    public function getControllerConfig()
    {
        return [
            'factories' => [
                Controller\CarrinhoController::class => function($container) {
                    return new Controller\CarrinhoController($container);
                },
            ],
        ];
    }
}

These are the codes that when the namespace and the folder name, start working.

config/modules.config.php:

<?php
return [
    'Zend\Log',
    'Zend\Mvc\Console',
    'Zend\Mvc\I18n',
    'Zend\Mvc\Plugin\FilePrg',
    'Zend\Mvc\Plugin\FlashMessenger',
    'Zend\Mvc\Plugin\Identity',
    'Zend\Mvc\Plugin\Prg',
    'Zend\Navigation',
    'Zend\Serializer',
    'Zend\ServiceManager\Di',
    'Zend\Paginator',
    'Zend\Cache',
    'Zend\Session',
    'Zend\Mail',
    'Zend\Form',
    'Zend\InputFilter',
    'Zend\Filter',
    'Zend\Hydrator',
    'Zend\I18n',
    'Zend\Router',
    'Zend\Db',
    'Zend\Validator',
    'AwsModule',
    'AssetManager',
    'Neilime\MobileDetect',
    'Carrinho',
    'Catalogo',
    'Cliente',
    'Geral',
    'Localidade',
    'Sitemap',
    //'Carrinho2',
];
  • One enters the post, should never have used zend, and downvote only because he did not understand the question, without even saying what problem she saw in the question for that... This community is to be congratulated.

  • You never checked the cache? I use zend 1 and it caches the routes so it has curled when it was giving error and even after being corrected the error persists.

  • Already checked yes @fajuchem, in the development environment is not caching the routes. =/

  • Shows the code of where you assemble the routes and where you make the links. Without the code it is difficult to help.

1 answer

0


I found that in the file config/modules.config.php, the order of modules in the array of namespaces of the project interferes in some way in the ZF3 in a way that did not interfere with ZF2. I noticed when I switched to Cart2, I was decoding his line that was at the end of array, while Cart was in the middle of array. I changed it so that Cart be in the same position as Cart2 and the problem was solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.