1

私は必死に ZF2 と戦ってきました。ルート ツリーを作成しようとしています。

  • /manual - 手動コントローラー、index アクションに移動します
  • /manual/[something] - 手動コントローラー、メーカーのアクションに移動します
  • /manual/[something]/[else] - 手動コントローラ、カテゴリ アクションに移動します
  • /manual/[something]/[else]/[foo] - 手動コントローラ、モデル アクションに移動します

私は公式ドキュメントと他のいくつかのウェブサイトを使用しましたが、私ができるのはトリガーだけです:

  • /manual - 手動コントローラー、index アクションに移動します
  • /manual/[something] - 手動コントローラ コンストラクタに移動しますが、アクションには移動しません...

他の2つはコントローラーにまったく到達しません....

        'manual' => array(
            'type' => 'literal',
            'options' => array(
                'route' => '/manual',
                'defaults' => array(
                    'controller' => 'Applicaton\Controller\Manual',
                    'action' => 'index'
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                // Segment route for viewing one blog post
                'manufacturer' => array(
                    'type' => 'segment',
                    'options' => array(
                        'route' => '/[:manufacturer]',
                        'constraints' => array(
                            'manufacturer' => '[a-zA-Z0-9_-]+'
                        ),
                        'defaults' => array(
                            'action' => 'manufacturer'
                        )
                    ),
                    'may_terminate' => true,
                    'child_routes' => array(
                        'category' => array(
                            'type' => 'segment',
                            'options' => array(
                                'route' => '/[:category]',
                                'constraints' => array(
                                    'category' => '[a-zA-Z0-9_-]+'
                                ),
                                'defaults' => array(
                                    'action' => 'category'
                                )
                            ),
                            'may_terminate' => true,
                            'child_routes' => array(
                                'model' => array(
                                    'type' => 'segment',
                                    'options' => array(
                                        'route' => '/[:model]',
                                        'constraints' => array(
                                            'model' => '[a-zA-Z0-9_-]+'
                                        ),
                                        'defaults' => array(
                                            'action' => 'model'
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        ),

事前にご協力いただきありがとうございます。どんな助けでも大歓迎です!

アップデート:

これが私のコントローラーアクションです:

public function manufacturerAction() {
    echo 'I am in the manufacturer action!';
    return new ViewModel();
}
4

1 に答える 1

2

正規表現を使用して実行できます。次のように、 module.config.phpのルートを変更します。

'manual' => array(
    'type' => 'Literal',
    'options' => array(
        'route' => '/manual',
        'defaults' => array(
            'controller' => 'Application\Controller\Manual',
            'action' => 'index',
        ),
    ),
),
'manufacturer' => array(
    'type' => 'Zend\Mvc\Router\Http\Regex',
    'options' => array(
        'regex' => '/manual/(?<manufacturer>[a-zA-Z0-9_-]+)',
        'defaults' => array(
            'controller' => 'Application\Controller\Manual',
            'action' => 'manufacturer',
        ),
        'spec' => '/manual/%manufacturer%',
    ),
),
'category' => array(
    'type' => 'Zend\Mvc\Router\Http\Regex',
    'options' => array(
        'regex' => '/manual/(?<manufacturer>[a-zA-Z0-9_-]+)/(?<category>[a-zA-Z0-9_-]+)',
        'defaults' => array(
            'controller' => 'Application\Controller\Manual',
            'action' => 'category',
        ),
        'spec' => '/manual/%manufacturer%/%category%',
    ),
),
'model' => array(
    'type' => 'Zend\Mvc\Router\Http\Regex',
    'options' => array(
        'regex' => '/manual/(?<manufacturer>[a-zA-Z0-9_-]+)/(?<category>[a-zA-Z0-9_-]+)/(?<model>[a-zA-Z0-9_-]+)',
        'defaults' => array(
            'controller' => 'Application\Controller\Manual',
            'action' => 'model',
        ),
        'spec' => '/manual/%manufacturer%/%category%/%model%',
    ),
),
于 2013-02-26T17:09:16.967 に答える