0

これは、アプリをルーティングするルートのダンプです。

[album] => Array([route] => Zend\Mvc\Router\Http\Segment Object
                            (
                                [parts:protected] => Array
                                    (
                                        [0] => Array
                                            (
                                                [0] => literal
                                                [1] => /album
                                            )
                                        [1] => Array
                                            (
                                                [0] => optional
                                                [1] => Array
                                                    (
                                                        [0] => Array
                                                            (
                                                                [0] => literal
                                                                [1] => /
                                                            )
                                                        [1] => Array
                                                            (
                                                                [0] => parameter
                                                                [1] => action
                                                                [2] => 
                                                            )
                                                    )
                                            )
                                        [2] => Array
                                            (
                                                [0] => optional
                                                [1] => Array
                                                    (
                                                        [0] => Array
                                                            (
                                                                [0] => literal
                                                                [1] => /
                                                            )
                                                        [1] => Array
                                                            (
                                                                [0] => parameter
                                                                [1] => id
                                                                [2] => 
                                                            )
                                                    )
                                            )
                                    )
                                [regex:protected] => /album(?:/(?P[a-zA-Z][a-zA-Z0-9_-]*))?(?:/(?P[0-9]+))?
                                [paramMap:protected] => Array
                                    (
                                        [param1] => action
                                        [param2] => id
                                    )
                                [defaults:protected] => Array
                                    (
                                        [controller] => Album\Controller\Album
                                        [action] => index
                                    )
                                [assembledParams:protected] => Array
                                    (
                                    )
                            )
                        [priority] => 0
                        [serial] => 3
                    )

しかし、私はこれを試してみると

  $router = $e->getRouter();
  $url = $router->assemble(array(), array('name' => 'Album\index'));

次のエラーが発生します。

「Album\index」という名前のルートが見つかりません

 Edit: here is route settings from module.config

   'router' => array(
    'routes' => array(
        'album' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/album[/:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id' => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Album\Controller\Album',
                    'action' => 'index',
                ),
            ),
        ),
    ),
),

編集:アドバイスに従って、次の変更を加えました

  'router' => array(
    'routes' => array(
        'album' => array(
            'type' => 'segment',
            'options' => array(
                'route' => '/album',
                'constraints' => array(
                    'action' => 'index',
//                        'id' => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Album\Controller\Album',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'process' => array(
                    'type' => 'Segment',
                    'options' => array(
                        'route' => '/[:action]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                        ),
                    ),
                ),
            ),
        ),
    ),
),

しかし、今はインデックスアクションを渡すことができないようです。私に見えるアルバムモジュールの唯一のアクションはインデックスであり、他に何をすべきかを修正/提案することはできませんか?

4

1 に答える 1