CakePHP3.1で追加されたRoutes Shellを試してみた
Routes Shell
はroutesを複雑に作っている場合等、CLIからroutesが正常に動くかをテストするときに使います。
URL解析チェック
以下のコマンドを実行することで、どのroutesに一致して、どうparseされるかを確認できます。
php bin/cake.php routes check /hoges/edit/1
// routesには以下が設定してあります。
// $routes->connect('/hoges/:action/*', ['controller' => 'fugas']);
実行結果
※Query Stringを含む場合はcheck対象のURLをダブルコーテーションで囲む必要があります。
php bin/cake.php routes check "/hoges/edit?key1=aaa&key2=bbb"
URL生成チェック
以下のコマンドを実行することで、どういうURLが生成されるかを確認することが出来ます。
php bin/cake.php routes generate controller:fugas action:edit 1
// routesには以下が設定してあります。
// $routes->connect('/hoges/:action/*', ['controller' => 'fugas']);
実行結果
> /hoges/edit/1