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'));

我收到以下错误。

找不到名称为“专辑\索引”的路线

 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

1

正如我猜测的那样,路线Album\index不存在。这是您的配置:

'router' => array(
    'routes' => array(
        'album' => array(  //<-- THIS is the ROUTE_NAME

你要找的是这个:

// AlbumController::indexAction()
$this->url('album');
$this->url('album', array('action' => 'index');

// AlbumController::listAction()
$this->url('album', array('action' => 'list');

// AlbumController::editAction() with param ID = 3
$this->url('album', array('action' => 'edit', 'id' => 3);

您使用的语法是 for child_routes。看这个例子

'router'       => array(
    'routes' => array(
        'album'     => array(
            'type'          => 'literal',
            'options'       => array(
                'route'    => '/album',
                'defaults' => array(
                    'controller' => 'album-controller-album',
                    'action'     => 'index'
                )
            ),
            'may_terminate' => true,
            'child_routes'  => array(
                'list'   => array(
                    'type'    => 'literal',
                    'options' => array(
                        'route'    => '/list',
                        'defaults' => array(
                            'action' => 'list'
                        )
                    )
                )
            )
        )
    )
)

以及相关的路由:

//AlbumController::indexAction()
$this->url('album');

//AlbumController::listAction()
$this->url('album/list');
于 2013-01-30T09:30:34.180 回答