2

私は自分のロートの設定を持っています:

  'admin' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '/admin[/[:controller[/:action]]]',
                'constraints' => array(
                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*/?',
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*/?',
                ),
                'defaults' => array(
                    'controller' => 'index',
                    'action' => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'query' => array(
                    'type' => 'Query',
                ),
            ),
        )

admin / controller / some_action?id = 234234234に移動しようとすると、エラーが発生します。

A 404 error occurred
Page not found.
The requested URL could not be matched by routing.

私の設定の何が問題になっていますか?

4

2 に答える 2

2

これらのパラメータを使用してルート設定を定義する場合:

//...
'defaults' => array(
                    'controller' => 'index',
                    'action' => 'Index',
                   ),
//...

コントローラ構成のレベルで、コントローラクラスがこのキーに関連付けられていることを確認する必要があります。

'controllers' => array(
        'invokables' => array(
            'index' => 'Your\Controller\Namespace\YourController',
            //...
        ),
    ),

ただし、より「構造化された」キーを定義することをお勧めします(異なるモジュールのレベルで異なるインデックスコントローラーがあると想像してください...)これは、コントローラーの名前空間に対応するキーを追加することで簡単に実現できます。

'defaults' => array(
                    'controller' => 'Index',
                    'action' => 'Index',
                    '__NAMESPACE__'=>'Your\Controller\Namespace'
                   ),

//...

//Controllers configuration

'controllers' => array(
        'invokables' => array(
            'Your\Controller\Namespace\Index' => 'Your\Controller\Namespace\YourController',
            //...
        ),
    ),

[編集]

この(構造化された)構成で試してください:

'admin' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/admin',
                'defaults' => array(
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                        ),
                    ),
                    'child_routes' => array(
                        'query'=>array(
                            'type'=>'Query',
                        )
                    )
                ),
            ),
        ),
于 2012-11-06T10:59:21.630 に答える
0

おそらくあなたが定義したあなたの正規表現:

'controller' => '[a-zA-Z][a-zA-Z0-9_-]*/?',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*/?',

これにより、末尾のスラッシュと一致するように強制されます。これを試してください。

'action'        => '[a-zA-Z][a-zA-Z0-9_-]*',
'controller'    => '[a-zA-Z][a-zA-Z0-9_-]*',
于 2012-11-06T14:17:35.847 に答える