Created
March 12, 2014 09:00
-
-
Save outrunthewolf/9503301 to your computer and use it in GitHub Desktop.
Dynamic routing Zend2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function onBootstrap( MvcEvent $e ) { | |
// Get the service and event managers | |
$events = $e->getApplication()->getEventManager(); | |
// Attach a dynamic render event | |
$events->attach(MvcEvent::EVENT_RENDER, function(MvcEvent $event) { | |
// Service Manager | |
$sm = $event->getParam('application')->getServiceManager(); | |
$mod = $sm->get('ModuleManager'); | |
// Add in a special route | |
foreach($mod->getModules() as $module) { | |
// Define some routes | |
$controller = __NAMESPACE__ . "Controller\BaseController"; | |
$routes = Segment::factory(array( | |
'route' => '/admin/test', | |
'defaults' => array( | |
'controller' => $controller, | |
'action' => 'index' | |
) | |
)); | |
if($module == "MyModule") | |
{ | |
$router = $sm->get('router'); | |
$router->addRoute($module, $routes, 1000); | |
var_dump($router->hasRoute($module)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment