0

I'm getting:

A 404 error occurred

Page not found. The requested URL could not be matched by routing.

My module.config.php file is:

'router' => array(
    'router' => array(
        'Test' => array(
            'type' => 'Segment',
            'options' => array(
                //http://localhost/Test/Test
                'route' => '/Test[/[:action]]',
                'constraints' => array(
                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
             ),
             'defaults' => array(
                 'controller' => 'Test\Controller\Test',
                 'action' => 'Test'
              ),
          ),
      ),
   ),
),

help please, i am new in Zend Framework 2 !

Community
  • 1
  • 1

6 Answers6

3

You should use configuration like Application module in ZendSkeletonApplication:

'router' => array(
    'routes' => array(
        'test' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/book',
                'defaults' => array(
                    '__NAMESPACE__' => 'Test\Controller',
                    'controller'    => 'Test',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                        ),
                    ),
                ),
            ),
        ),
    ),
),

You just add the following code:

'test' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '[/:action][/:id]',
                        'constraints' => array(
                            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id'     => '[0-9]*',
                        ),
                        'defaults' => array(
                            '__NAMESPACE__' => 'Test\Controller',
                            'controller'    => 'Test',
                            'action'        => 'index',
                        ),
                    ),
                ),

add this code to 'child-routes' key and after that you'll access to url: localhost/:controller_name/:action_name/:id (example : http://zf.dev/test/index or http://zf.dev/test/add/1). And now it's work! This code can fix error 404 for tutorial in zf2 documentation.

2

You have a typo, try this:

'router' => array(
    'routes' => array(

Routes rather than router twice..

Andrew
  • 12,617
  • 1
  • 34
  • 48
  • thanks, for you answer friend, i add routes and : Fatal error: Class 'Test\Controller\TestController' not found in D:\wamp\www\zf\web\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php on line 17 – Juan Castro Lurita Feb 19 '13 at 15:48
  • Have you made an invokable for your controller?: 'controllers' => array( 'invokables' => array( 'Test' => 'Test\Controller\TestController', – Andrew Feb 19 '13 at 15:50
  • You also need to make sure your controller actually exists :) – Andrew Feb 19 '13 at 15:50
  • yes, i have: return array( 'controllers' => array( 'invokables' => array( 'Test\Controller\Test' => 'Test\Controller\TestController' ), ), – Juan Castro Lurita Feb 19 '13 at 15:53
  • can you post some controller code? Have you got the namespace correct inside the controller class? – Andrew Feb 19 '13 at 16:04
  • hello andrew, my controller code: – Juan Castro Lurita Feb 19 '13 at 16:10
1

Achieve fix it, I was missing the letter "d", was thus: Zend \ Loader \ StandarAutoloader I added the "d": Zend \ Loader \ StandardAutoloader. Greetings Friends. TIP: Zend Studio 10 and his version de ZF2 run perfect for this moment !

0

Please check the .htaccess file and index.php files. If these are exist in public folder means, you have to use the url as

 http://localhost/public/Test/Test.

Your codes are almost right. Andrew has guided you well. Let me know your response.

user2003356
  • 445
  • 2
  • 11
  • 24
  • thanks for you answer, i have this in my .htacces : RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ RewriteRule ^(.*)$ - [E=BASE:%1] RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] – Juan Castro Lurita Feb 19 '13 at 16:06
  • Have you included the Module name in application.config.php file. 'modules' => array( 'Test', ), – user2003356 Feb 19 '13 at 16:09
  • hi, user2003356 i have this in my application.config.php file array( 'Application', 'Test' ), 'module_listener_options' => array( 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ), 'module_paths' => array( './module', './vendor', ), ), ); – Juan Castro Lurita Feb 19 '13 at 16:21
  • Please call this url. http://localhost/test/test. Convert uppercase characters to lowercase. And please update, where do you placed the htaccess file. – user2003356 Feb 19 '13 at 16:23
  • i test this http://localhost/Test/Test and : Not Found The requested URL /Test/Test was not found on this server. , my .htacces file is in the public folder of my Zend Framework , – Juan Castro Lurita Feb 19 '13 at 16:30
  • No. Please understand Juan. I asked to call this url. localhost/test/test. Please change the UPPERCASE T to LOWERCASE t. – user2003356 Feb 19 '13 at 16:34
  • ok, i change the UPPERCASE T to LOWERCASE t and : Not Found The requested URL /test/test was not found on this server. – Juan Castro Lurita Feb 19 '13 at 16:56
  • Check the Application module codes from top to bottom. So that you can fix. – user2003356 Feb 19 '13 at 17:04
  • :c, i have this: array( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } } – Juan Castro Lurita Feb 19 '13 at 17:10
  • can you able to run application module in your server? – user2003356 Feb 19 '13 at 17:13
  • i am new in ZF2 and do not know if I'm missing something to run modules frankly, I use Zend Studio 10 and I created a new project Zend Framework Project, my zend studio 10 comes with ZF 2.1.0. – Juan Castro Lurita Feb 19 '13 at 17:17
  • please download ZF2's sample application - skeleton album application. It helps you to know ZF2 workflow. Please do it. I'll help you. – user2003356 Feb 19 '13 at 17:23
  • oks'll see that and anything I write again in this post, friend, thanks for the help today. – Juan Castro Lurita Feb 19 '13 at 17:38
0

1.You should check also application.config.php and add your module name into RETURN array.

return array(    
    'modules' => array(
        'Application',
        'your_module',
        .....    
 ),

2.If Doesn't.Check route array in module.config.php

Saro Taşciyan
  • 5,210
  • 5
  • 31
  • 50
UWU_SANDUN
  • 1,123
  • 13
  • 19
0

I will suggest also check the data folder that has cached config files, config files being cached in dev install also may cause this issue. delete files inside data/cache and try.

PS: if you are just starting try with blog module on zend site it is for beginners and more updated with new versions.

https://framework.zend.com/manual/2.4/en/in-depth-guide/first-module.html

Anupam Rekha
  • 180
  • 9