4

I'm currently using the ZendFrameworkSkeleton application from Git and am trying to utilize the module part of it to have a multitude of modules, changeable by URL like so:

http://localhost/application/index/index/
http://localhost/guestbook/index/index/
http://localhost/forum/index/index/

Also, how would you use language in there as well for future expansion:

http://localhost/en/application/index/index/
http://localhost/de/application/index/index/
http://localhost/en/forum/index/index/

I would have thought this was pretty much the whole point of ZF2 Modules and am surprised it doesn't seem to work out of the box. Anyone got any idea how this is meant to be done or perhaps a link to an example/tutorial of it?

At the moment it appears that the Router is within each Module rather than the entire entire Application, which I would have thought was how it should be done... I'm sort of guessing that you have one Application module that does the routing and the global stuff, injecting dependencies and what not and then other modules for the different stuff like game, account, guestbook, forum etc.

Once I've figured it out I can make a Github example application of it as I know other people are curious about it.

Edit @ 24/11/2011: I've since come across a post by EvanDotPro on the contributor forum about them talking about them not wanting to do the ZF1 module/controller/action way of doing things and that there wasn't that much demand for it. He actually wrote an example that had it running something like this but said it didn't work 100%. So anyone who comes across this post looking for more information and are a little more savvy then this is it: https://github.com/EvanDotPro/EdpMagicRoute (if it still exists at point of reading this!)

Stoyan Dimov
  • 5,250
  • 2
  • 28
  • 44
creamcheese
  • 2,524
  • 3
  • 29
  • 55
  • 2
    Sounds like something you'd accomplish through custom routing – Phil Nov 10 '11 at 13:24
  • I thought it would be as easy as adding soemthing like: /%module%/%controller%/%action%/ but it doesn't seem to work – creamcheese Nov 10 '11 at 14:44
  • Hmm, did a search and couldn't find anything. Could merge these two then I guess... not really sure how to. – creamcheese Nov 10 '11 at 22:05
  • After having used the module/controller/action for quite a while in ZF1 and having used controller/action a fair bit in ZF2 I would say that having module/controller/action is quite overkill and forces you to have unnecessarily long URLs – creamcheese Apr 21 '12 at 13:44

3 Answers3

4

I found nice example on github https://github.com/akrabat/zf2-tutorial + pdf with explanation http://akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework-2.pdf

Nikolai Senkevich
  • 2,370
  • 2
  • 19
  • 29
  • Thanks, for zf2-tutorial, I've searched many examples but can not find form usage anywhere but here. – rdo May 21 '12 at 16:00
4

To change routing you need to edit Application/confid/module.config.php. Find there and change to

'options' => array(
    'route' => '/[:module/[:controller[/:action]]]', 
    'constraints' => array(
        'module' => '[a-zA-Z][a-zA-Z0-9_-]*', 
        'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
        'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
    ), 
    'defaults' => array(
        'module' => 'Application', 
        'controller' => 'index', 
        'action' => 'index'
    )
)

You can see I added /[:module and deafults and constraint

Sergey Romanov
  • 2,949
  • 4
  • 23
  • 38
1

You can use 'child_routes' attribute in module.config.php file comes under module\Application\config

'routes' => array(
        'application' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/application',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Index',
                    '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(
                        ),
                    ),
                ),
            ),
        ),
    ),

then you can run localhost/application/index/index

sandy
  • 11
  • 3