Dante
Dante

Reputation: 101

zend framework 2 list modules in layout

I want to have a plug-in system (like wordpress ) , How can I list my admin controller in layout.phtml ?

Upvotes: 1

Views: 1100

Answers (1)

Jurian Sluiman
Jurian Sluiman

Reputation: 13558

The list of modules if available in the module manager (Zend\ModuleManager\ModuleManager). You can get the module manager via the service locator. For example in your controller:

class MyController extends AbstractActionController
{
    public function indexAction()
    {
        $manager = $this->getServiceLocator()->get('ModuleManager');
        $modules = $manager->getLoadedModules();
    }
}

The controllers have access to the layout (and its parameters) via the layout controller plugin.

$this->layout()->modules = $modules;

An alternative is that you create a view helper. In this view helper, you get the module manager and then return the list of modules.

Upvotes: 4

Related Questions