Dante
Dante

Reputation: 101

get some of my controllers in zend framework 2

I am createing a cms based on zend framework 2 . I have som modules , let's say News module. It has two controllers one for backend and one for front page :

News Module :
-- AdminController 
-- IndexController

My question is How can I list all AdminControllers in my admin module ? I think it can be achieved by event manager but I don't know how

Thanks in advance

Upvotes: 0

Views: 47

Answers (1)

Sam
Sam

Reputation: 16445

Your Admin module does this:

  • check a config key (i.e. super_cms)
  • check if a subkey exists (i.e. controllers)
  • foreach entries in said subkey, list them on your webpage

Your News module does this:

//module.config.php
return [
    'super_cms' => [
        'controllers' => [
            'NewsModule\Controller\AdminController' => [
                'label'      => 'News',
                'permission' => 'Admin',
                'route'      => 'news/admin'
            ]
        ]
    ]
];

Now with this setup, you could do a foreach on the controllers and create a navigation that has all your controllers listed that you need. You could specify dedicated label options, you could assign permission keys that are required for access or you could assign a dedicated route to call.

This is all up to you tho. But without configuration, nothing works. There are "magic" ways, yes, but they would all require you to recursively scan lots and lots of directories which you don't want! Seriously, you don't!

Upvotes: 1

Related Questions