0
votes

I'm just starting with ZF2. I installed ZF2, created the VirtualHost and I'm able see the welcome page. Then I added a new module in the module directory and then added the module name in the application.config.php but every time it says

Not Found

The requested URL /application was not found on this server.

ZF2 comes with a default module called application, so if I hit the URL like "virtuaHostName/application" then also it should show the welcome page right? but I'm seeing that same "Not found" message.

4

4 Answers

1
votes

Do not misinterpret ModuleNames for RouteNames. If you take a look inside module.config.php you'll see an array in the following syntax:

'router' => array(
    'routes' => array(
        '$routeName' => array(
            // $routeParams 
        )
    )
)

In this case $routeName of course always will be a string that defines the NAME of a route. To know which URL is attached to that route, you got to look at the $routeParams. This usually looks like the following:

'type' => '$routeType',
'options' => array(
    'route' => '$theRoute'
)

The $routeType always is a string, too. Here people usually add one of the shortnames for the routetype that are defined here (scroll up a little). Alternatively the full classname to the specific route could be given, too.

Inside the options array you'd define the options that a route needs. One will always be route, as this is the matching criteria for a route. Following example:

'route' => '/test'
Matching URL: http://myproject.dev/test

There's one catch however and that is child-routes. When there are child-routes, the route option gets attached to it's parent routes. So for example:

'route' => '/test'   // <- This is the PARENT Route
'route' => '/foobar' // -< This is the CHILD Route
Matching URL: http://myproject.dev/test/foobar

Hope this helps you out a little with understanding the framework routing. More information can always be gathered from the official Documentation of Zend\Mvc\Router

1
votes

To add any new module you need to define new module name in follwing array in application.config.php file in config folder. Suppose you need to add new module 'Admin'. You can set that here as follows:

return array(
'modules' => array(
    'Application',
    'Admin',
),

Note: Application is the default module.

0
votes

Add the module name in application.config.php then add the route in module.config.php. Of couse you have to add the invoke controller in "invokables" array in module.config.php

0
votes

To add/create any new module in zend framework 2. it provide ZFTool to do this worked by a simple some steps.

1) download ZFTool to official site of zend framework. 2) extract it in root folder of you project. 3) access it by command by(path to project>php zftool/zf.php create module module name project path)

you can get more detail on

https://www.youtube.com/watch?v=8BNg2zPzEmI&index=5&list=PLMoDvYQTYOX3C1WZvNVLm7u3YTRvR5Zhs