5

Zend Framework 2を使用してアプリケーションで定義したすべてのルートを簡単に一覧表示するにはどうすればよいですか?

「ルート」とは、以下で定義されているものを意味します。

module/[moduleName]/config/module.config.php

'router' => array(
    'routes' => array(
        ...
    )
)

それらをすべてリストする必要がありますが、これを簡単に行う方法がわかりません。ドキュメントもフォーラムも今では役に立ちません。

4

4 に答える 4

2

すべてのルートを取得するには、ZFToolを使用します

ルートのダンプを取得するコンソール コマンド:

php vendor/bin/zf.php config list | grep routes

Windows ユーザーの場合 (未テスト):

php vendor/bin/zf.php config list |  findstr /R /C:"[routes]"
于 2015-03-07T10:48:26.050 に答える
0

BjyAuthorize の ACL セットアップをさまざまな状況でそれぞれ使用できるように、モジュールごとにルートを区別する必要がありました。

これには複数の方法がありますが、Jurian Sluimanが示したように、すべてのルートを読み込む (変数が変更されています):

<?php

// $this->services instanceof Zend\ServiceManager\ServiceManager

$config = $this->services->get('Config');
$routes = $config['router']['routes'];

関数内のモジュールごとに後で区別するために、次のように取得できます。

<?php

// $this->services instanceof Zend\ServiceManager\ServiceManager

/**
 * Load the Application's active modules.  
 * @note May need to specify additional modules that may not be 
 * loaded at this runtime.
 */
$moduleManager = $this->services->get('ModuleManager');
$moduleManager->loadModules();

// Retrieve array of module names.
$modules = $moduleManager->getModules();

// Setup a container for all active routes.
$routes = []; 

// Build array of all active routes.
foreach ($modules as $moduleName) {
    $module = $moduleManager->getModule($moduleName);
    $routes[$moduleName] = array_keys($module->getConfig()['router']['routes']);
}
// Whatever you care to do with them.
echo $routes;
于 2015-08-01T00:52:01.477 に答える