Question

I have been following the tutorial from Zend (http://www.youtube.com/watch?feature=player_embedded&v=EerB9bTvqrY) however when I add a new Module in my project I can not navigate to it, are the instructions in this tutorial incorrect?

Basically when I add a new Module in Zend Studio to my Zend Framework project I can not navigate to it, my new module is called "deals". I navigate to localhost/dealproject/deals and I get error 404. When navigating to localhost/dealproject/ it loads the zend skeleton application page correctly.

Thanks for your help.

module.config.php

<?php
return array(
'controllers' => array(
    'invokables' => array(
        'Deals\Controller\Deals' => 'Deals\Controller\DealsController',
    ),
),
'router' => array(
    'routes' => array(
        'deals' => array(
            'type'    => 'Literal',
            'options' => array(
                // Change this to something specific to your module
                'route'    => '/deals',
                'defaults' => array(
                    // Change this value to reflect the namespace in which
                    // the controllers for your module are found
                    '__NAMESPACE__' => 'Deals\Controller',
                    'controller'    => 'Deals',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                // This route is a sane default when developing a module;
                // as you solidify the routes for your module, however,
                // you may want to remove it and replace it with more
                // specific routes.
                '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(
                        ),
                    ),
                ),
            ),
        ),
    ),
),
'view_manager' => array(
    'template_path_stack' => array(
        'Deals' => __DIR__ . '/../view',
    ),
),

);

Was it helpful?

Solution 2

To me the route configuration looks correct and it should show results. What I noticed is that your base URL (localhost/dealproject/) for the ZF2 application is in a sub directory of the domain's root. As you probably know all the requests are mapped to the index.php of your application (~/public/index.php). This is done by some configuration in your .htaccess file (in the same directory).

In the example URL www.example.com/blog if blog doesn't exists as a folder under www.example.com's root you get a 404 Page not found. However, the .htaccess of ZF2 makes apache call the index.php in the domain's root if no directory is found (this assumes you use the ZendSkeletonApplication).

Now, since your index.php is not in the domain root (localhost/) but in localhost/dealproject/ and your .htaccess is (I assume) in localhost/dealproject/ as well, when you call localhost/dealproject/deals apache is looking for a directory dealproject/deals since in localhost there is no .htaccess to prepare the necessary configuration.

I would advise you to make dealproject folder the root of localhost. This will enable you to call your route like this: localhost/deals and .htaccess and index.php will be processed correctly.

Hope this helps :)

Stoyan

OTHER TIPS

Make sure you've enabled the module in ~/config/application.config.php

'modules' => array(
    'Application',
    'Deals',
),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top