Php 如何在ControllerFactory zend 2中获取参数?

Php 如何在ControllerFactory zend 2中获取参数?,php,zend-framework,zend-framework2,factory,zend-route,Php,Zend Framework,Zend Framework2,Factory,Zend Route,我有一个简单的工厂,我想从这里获取参数: <?php namespace Webb\Factory; use Zend\Mvc\Controller\AbstractActionController; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; use Webb\Controller\IndexController; class IndexCon

我有一个简单的工厂,我想从这里获取参数:

<?php
namespace Webb\Factory;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Webb\Controller\IndexController;



class IndexControllerFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator){

    $allservices = $serviceLocator->getServiceLocator();
    $sm = $allservices->get('ServiceManager');


    $IndexController = new IndexController();
    $IndexController->setProjectTable($sm->get('project-table'));
    $IndexController->setCategories($sm->get('categories-table'));
    $IndexController->setPages($sm->get('pages-table'));
    $IndexController->setUrls($sm->get('urls-table'));

    return $IndexController;
}

}
但它返回错误 Zend\Mvc\Controller\ControllerManager::get无法获取或创建路由器的实例

我是zend 2的新手。请帮忙


关于

您需要获取当前MvcEvent对象,以便从那里获取RouteMatch对象。请尝试以下代码:

$application = $allservices->get('Application');
$routeMatch = $application->getMvcEvent()->getRouteMatch();
我假设$allservices是代码中的顶级服务管理器

$application = $allservices->get('Application');
$routeMatch = $application->getMvcEvent()->getRouteMatch();