3
votes

hi i am new in zend framework2.2.0. i want to create one module with multiple controller i have download "Album" module from github and its working fine Now i want to add the more controller in it the below i have shown my folder structure for file in module

module/
    Album/
         config/
             module.config.php
         src/
            Album/
                Controller/
                         AlbumController.php
                         UserController.php
               Form/
                     AlbumForm.php
                     UserForm.php
               Model/
                   AlbumTable.php 
                   Album.php
                   UserTable.php 
                   User.php

        view/
            album/ 
                 album/             
                       index.phtml
                 user/             
                       index.phtml

i have also changed all the name space in file

namespace Album\Controller;

class UserController extends \Zend\Mvc\Controller\AbstractActionController

and some indexAction method witch returns a new \Zend\View\Model\ViewModel();

then you can create your viewfile in

Album/view/Album/user/index.phtml i did above changes. is there any chage needed in "Album/Module.php" file ? can you tell me through which link i can see users list ?

i and tired with this error help me to get out of it

enter image description here

1
Which error ? I don't see any error message hint in your question.kuldeep.kamboj
if it successfull so through which link i can see the users list ? "/album/user" or directly "/user" ?deck john

1 Answers

9
votes

You may need to add url rules for user in module.config.php in Album/config folder. Then you can access the url like

// The following section is new and should be added to your file
'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',
                ),
            ),
        ),
        'user' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/user[/:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Album\Controller\User',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),

Also

'controllers' => array(
    'invokables' => array(
        'Album\Controller\Album' => 'Album\Controller\AlbumController',
        'Album\Controller\User' => 'Album\Controller\UserController',
    ),
),