0

このトピックの推奨事項に従おうとしました: zend Framework 2 + ルーティング データベース

私はルートクラスを持っています:

    namespace Application\Router;

use Zend\Mvc\Router\Http\RouteInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\Mvc\Router\RouteMatch;

class Content implements RouteInterface, ServiceLocatorAwareInterface {

protected $defaults = array();
protected $routerPluginManager = null;

public function __construct(array $defaults = array()) {
    $this->defaults = $defaults;
}

public function setServiceLocator(\Zend\ServiceManager\ServiceLocatorInterface $routerPluginManager) {
    $this->routerPluginManager = $routerPluginManager;
}

public function getServiceLocator() {
    return $this->routerPluginManager;
}

public static function factory($options = array()) {
    if ($options instanceof \Traversable) {
        $options = ArrayUtils::iteratorToArray($options);
    } elseif (!is_array($options)) {
        throw new InvalidArgumentException(__METHOD__ . ' expects an array or Traversable set of options');
    }

    if (!isset($options['defaults'])) {
        $options['defaults'] = array();
    }

    return new static($options['defaults']);
}

public function match(Request $request, $pathOffset = null) {
    if (!method_exists($request, 'getUri')) {
        return null;
    }

    $uri = $request->getUri();
    $fullPath = $uri->getPath();

    $path = substr($fullPath, $pathOffset);
    $alias = trim($path, '/');

    $options = $this->defaults;
    $options = array_merge($options, array(
        'path' => $alias
            ));

    return new RouteMatch($options);
}

public function assemble(array $params = array(), array $options = array()) {
    if (array_key_exists('path', $params)) {
        return '/' . $params['path'];
    }

    return '/';
}

public function getAssembledParams() {
    return array();
}

}

match() 関数は Zend\Mvc\Router\RouteMatch のインスタンスのオブジェクトを返すことに注意してください。ただし、ファイル Zend\Mvc\Router\Http\TreeRouteStack では、オブジェクトが RouteMatch のインスタンスであることを確認します (名前空間のプレフィックスなし)。

if (
    ($match = $route->match($request, $baseUrlLength, $options)) instanceof RouteMatch
            && ($pathLength === null || $match->getLength() === $pathLength)
        )

私の場合、名前空間のために条件が失敗します。

助言がありますか?

4

1 に答える 1