简体   繁体   中英

ZendSkeleton 404 error - The requested URL could not be matched by routing

So I've been following the fairly straightforward zend 2 skeleton example "album". I followed every step to the teeth and yet I cannot escape the 404 Error - requested URL could not be matched by routing whenever I input http://hostname/album for indexing, or http://hostname/album/add for adding, etc.

Naturally I looked into the routing found in the module.config.php file:

 <?php
 return array(
 'controllers' => array(
     'invokables' => array(
         'Album\Controller\Album' => 'Album\Controller\AlbumController',
     ),
 ),
 'router' => array(
     'routes' => array(
         'album' => array(
             'type'    => 'segment',
             'options' => array(
                 'route'    => '/album[/:action][/:id]',
                 'constraints' => array(
                     'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                     'id'     => '[0-9]+',
                 ),
                 'defaults' => array(
                     'controller' => 'Album\Controller\Album',
                     'action'     => 'index',
                 ),
             ),
         ),
     ),
 ),
 'view_manager' => array(
     'template_path_stack' => array(
         'album' => __DIR__ . '/../view',
     ),
 ),
);

Everything here looked fine, so I looked into the Module.php where the module.config.php is getting loaded from:

 <?php
  namespace Album;

  use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
  use Zend\ModuleManager\Feature\ConfigProviderInterface;

  class Module implements AutoloaderProviderInterface, ConfigProviderInterface
  {
      public function getAutoloaderConfig()
      {
         return array(
         'Zend\Loader\ClassMapAutoloader' => array(
             __DIR__ . '/autoload_classmap.php',
         ),
         'Zend\Loader\StandardAutoloader' => array(
             'namespaces' => array(
                 __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
             ),
         ),
     );
     }

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

Again, everything looks fine here. Now I thought maybe the problem is that I didn't include the Album module in the application.config.php file (comments removed):

<?php
return array(

'modules' => array(
    'Application',
    'Album',
),

'module_listener_options' => array(

    'module_paths' => array(
        './module',
        './vendor',
    ),

    'config_glob_paths' => array(
        'config/autoload/{{,*.}global,{,*.}local}.php',
    ),

);

However it is included. I also have the AlbumController.php and the view (.phtml) files exactly where they should be. I double checked the paths multiple times yet the routes still do not work. Any ideas? Any suggestion would be appreciated.

PS - I am using a Ubuntu 14.04 Virtual Box.

EDIT

Here's the directory structure for the application: (I'm just listing the relevant files/folders to make it more readable)

  • ZendSkel
    • public
      • index.php
    • config
      • application.config.php
    • module
      • Application
      • Album
        • Module.php
        • config
          • module.config.php
        • src
          • Album
            • Controller
              • AlbumController.php
            • Model
            • Form
        • view
          • album
            • album
              • index.phtml
              • add.phtml
              • edit.phtml
              • delete.phtml

Also, I am using virtual host with apache2.2.

For anyone, who is still looking for solution of this problem,

Clearing the data/cache folder, allowed routing to work as expected.

Like @Mayank Awasthi said:

Clearing the data/cache folder, allowed routing to work as expected.

This applies to Zend AND Laminas.

If the issue is not cache related, check your config and routing files!

If you follwoing the tutorial in the official page step by step and it shows 404. make sure 1- stop the serve, 2- enter "composer development-enable". 3- enter "composer serve" and then it should work. The tutorial does mention "composer development-enable" but it doesnt mention it in the right order, reason why a lot of people keep getting the 404

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM